1 Setup and implementation code for a void function Max You

(1) Set-up and implementation code for a void function Max

You are not required to write a complete C++ program but must write your responses to the specific function related questions below.

Q1: Write the heading for a void function called Max that has three int parameters: num1, num2, and greatest. The first two parameters receive data from the caller, and greatest returns or updates a value. Note that greatest should be a reference parameter. Document the data flow of the parameters with appropriate comments.

Q2: Wirte the function prototype for the function in Q1

Q3: Write the function definition of Q1 so that it returns the greatest of the two input parameters to (or through) the greatest reference parameter

Q4: Add comments to the function definition you wrote in Q3 that also states its pre condition and post condition.

Solution

//Q1: Write the heading for a void function called Max that has three int parameters: num1, num2, and greatest.
//The first two parameters receive data from the caller, and greatest returns or updates a value.
void Max(int num1, int num2, int &greatest);  
//Q3: Write the function definition of Q1 so that it returns the greatest of the
//two input parameters to (or through) the greatest reference parameter
void Max(int num1, int num2, int &greatest)
{
//Q4: Add comments to the function definition you wrote in Q3 that also states its pre condition and post condition.
//If num1 is greater than num2 assign num1 to greatest, else assign num2 to greatest.
greatest = num1 > num2 ? num1 : num2;
}

(1) Set-up and implementation code for a void function Max You are not required to write a complete C++ program but must write your responses to the specific fu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site