Do each of the following in the main function:
a) Write the function prototype for function zero, which takes a double array big_nums and does not return a value.
b) Write the function call for the function in part a.
c) Write the function prototype for function add1AndSum, which takes an integer array one_small and returns an integer.
d) Write the function call for the function described in part c.

Respuesta :

Answer:

a)

void zero(double big_nums[]);  

b)

zero(big_nums)  

c)

int add1AndSum (int one_small[]);

d)

add1AndSum(one_small);

Explanation:

a)

void zero(double big_nums[]);  

in this statement:

zero is the name of the function

void is used as the function does not return a value.

The function zero takes an array parameter i.e. big_nums[]

big_nums is the name of the array

big_nums[] array has a data type double

b)

zero is the name of the function

In part a) function zero has a parameter which is the array big_nums. So in order to call this function an array has to be passed as a parameter to this function.

So in this statmenent zero(big_nums) the array big_nums is passed to the zero function. You can also declare a new  double type array with a different name in main() function and can pass this to the zero function as:

double array[ ] = { 20.6, 30.8, 5.1};

zero(array);

Look at the following program for the better understanding of part a) and b)

#include <iostream>   //for using input output functions

using namespace std;  //to access objects like cin cout

void zero (double big_nums[]);   // function prototype

int main() {  //start of main() function

double a[ ] = { 20.6, 30.8, 5.1};  // double type array a with elements

zero(a);    }   //calls zero function passing array a to the function

void zero(double big_nums[]){      // function zero with double type array big_nums as parameter and the function returns no value

   int i;    

   for(i=0;i<3;++i)     {

        cout<<big_nums[i];     }  }  //prints the elements of array

c)

add1AndSum is the name of the function

int is used as the function does not return an integer.

The function add1AndSum takes an integer array parameter i.e. one_small[]

one_small is the name of the array

one_small[] array has a data type int

d)

add1AndSum is the name of the function

In part c) function add1AndSum has a parameter which is the array one_small. So in order to call this function an array has to be passed as a parameter to this function.

So in this statement add1AndSum(one_small); the array one_small is passed to the add1AndSum function. You can also declare a new  int type array with a different name in main() function and can pass this to the add1AndSum function.

Ver imagen mahamnasir