Question
Add 3 ===== Name the source file for this section add3.cpp. Write a function named add3 which takes as arguments an array of integers and
Add 3 ===== Name the source file for this section add3.cpp.
Write a function named "add3" which takes as arguments an array of integers and an integer representing the size of the array. The function should not return anything, i.e. it should have a return type of void. The function should change the contents of the array argument it received so that each element has 3 added to it.
Write a function named main which outputs the result of testing your function with 5 different inputs. An example main::
int main() { const int SIZE = 3; int a[SIZE] = {1, 2, 3}; int b[SIZE] = {4, 5, 6}; int c[SIZE] = {3, 3, 3}; int d[SIZE] = {-1, 0, 1}; int e[SIZE] = {99, 32, 49};
add3(a, SIZE); add3(b, SIZE); add3(c, SIZE); add3(d, SIZE); add3(e, SIZE);
cout a[0] == 4 && a[1] == 5 && a[2] == 6 << endl; cout b[0] == 7 && b[1] == 8 && b[2] == 9 << endl; cout c[0] == 6 && c[1] == 6 && c[2] == 6 << endl; cout d[0] == 2 && d[1] == 3 && d[2] == 4 << endl; cout e[0] == 102 && e[1] == 35 && e[2] == 52 << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started