Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the function definition for a void function called Max that has three int

ID: 3694048 • Letter: W

Question

Write the function definition for a void function called Max that has three int parameters: num 1, num 2, and greatest. The first two parameters receive data from the caller, and the greatest returns value of max of num 1 and num 2. Document the data flow of the parameters with appropriate comments int the function heading. Write a code segment that read a series of positive integers from an input file stream variable called indata and print a row of ampersand (&) using cout for each number read.(Assume indata is declared and opened with a disk file.)

Explanation / Answer

14.

/*Max a function which receives 3 parameters, the first 2 parameters are
passed by value, where as the third parameter is passed by reference.*/
void Max(int num1, int num2, int &greatest)
{
greatest = (num1 > num2) ? num1 : num2;
}

15.

while(!indata.eof())   //Till the end of the file.
{
indata>>num;       //Read each number.
for(int i = 1; i <= num; i++)   //Loop runs for num number of times.
cout<<"&";   //Prints & each time.
cout<<endl;   //After num &'s are printed, move to next line.
}