Question

In: Computer Science

C++ Functions There are many reasons why one would want to know the minimum and the...

C++ Functions

There are many reasons why one would want to know the minimum and the maximum of a series of values: fight control, range determinate, even in academia, professors often seek the distribution of grades on homework, exams, and class grades.

For this lab, you will write a program which will include a minimum function and a maximum function. Both functions should take in three values. The minimum function should return the minimum of the three values and the maximum should return the maximum of the three values.

The values should be entered by the user.

So, at the very latest, your program should have three functions:

- main()

- minimum()

- maximum()

Beyond that, feel free to modularize your code as you wish.

Solutions

Expert Solution

Screenshot of the code:

Sample Output:

Code to copy:

//Include required header file.

#include <iostream>

//Use the standard naming convention.

using namespace std;

//Define the function maximum() having three integer

//values.

int maximum(int num1, int num2, int num3)

{

//Declare and initialize required variables.

int maxNum = 0;

//If num1 is greater than or equal to num2 and num3,

//then make num1 as maximum number.

if((num1 >= num2) && (num1 >= num3))

{

    maxNum = num1;

}

//If num2 is greater than or equal to num1 and num3,

//then make num2 as maximum number.

if((num2 >= num1) && (num2 >= num3))

{

    maxNum = num2;

}

//If num3 is greater than or equal to num1 and num2,

//then make num3 as maximum number.

if((num3 >= num1) && (num3 >= num2))

{

    maxNum = num3;

}

//Return the maximum of the three values given in

//the function.

return maxNum;

}

//Define the function minimum() having three

//integer values.

int minimum(int num1, int num2, int num3)

{

//Declare and initialize required variables.

int minNum = 0;

//If num1 is less than or equal to num2 and num3,

//then make num1 as minimum number.

if((num1 <= num2) && (num1 <= num3))

{

    minNum = num1;

}

//If num2 is less than or equal to num1 and num3,

//then make num2 as minimum number.

if((num2 <= num1) && (num2 <= num3))

{

    minNum = num2;

}

//If num3 is less than or equal to num1 and num2,

//then make num3 as minimum number.

if((num3 <= num1) && (num3 <= num2))

{

    minNum = num3;

}

//Return the minimum of the three values given in

//the function.

return minNum;

}

//Start the execution of the main() method.

int main()

{

//Declare required variables.

int val1, val2, val3, minVal, maxVal;

//Prompt the user to enter three integer values.

cout << "Enter three values:" << endl;

cin >> val1 >> val2 >> val3;

  

//Call the function maximum() by passing these three

//values and store the returned value into the

//variable maxVal.

maxVal = maximum(val1, val2, val3);

//Call the function minimum() by passing these three

//values and store the returned value into the

//variable minVal.

minVal = minimum(val1, val2, val3);

//Display the maximum value among these three values.

cout << "The maximum of three values is: " << maxVal;

cout << endl;

//Display the minimum value among these three values.

cout << "The minimum of three values is: " << minVal;

cout << endl;

return 0;

}


Related Solutions

List as many reasons as you can for why a firm would want to differentiate its...
List as many reasons as you can for why a firm would want to differentiate its products from its competitors. Why might a firm choose a product similar to its competitor??answer in 100 words)
Why would an organization want to know what the role of a credit portfolio is?
Why would an organization want to know what the role of a credit portfolio is?
Discuss the reasons why an organization would want to successfully socialize a new employee and the...
Discuss the reasons why an organization would want to successfully socialize a new employee and the benefits. Give some examples of socializing employees. (A paragrph explaining this concept is good).
Would you want to know if your spouse or lover cheated on you? Why or why...
Would you want to know if your spouse or lover cheated on you? Why or why not ? Does being married make a difference in how you feel about this issue? Why or why not?
Provide five reasons why a firm would want to acquire another firm. Explain why most acquisitions...
Provide five reasons why a firm would want to acquire another firm. Explain why most acquisitions are unsuccessful.
Corporate Governance List and describe in detail three reasons why a company would want to engage...
Corporate Governance List and describe in detail three reasons why a company would want to engage in a robust corporate social responsibility plan. How does retrograde analysis help a company determine how it will engage in corporate social responsibility? Scalability is often noted as the biggest opportunity in the market. Describe in detail two ways that a company can scale up its corporate social responsibility efforts – and to what end they would attempt to scale up such efforts.
1. Why would you want to sell a company? What are some valid reasons to do...
1. Why would you want to sell a company? What are some valid reasons to do so? Justify your answer.
Why would you want to change yourself rather than others? What are some of the reasons...
Why would you want to change yourself rather than others? What are some of the reasons change is difficult? How might you develop the use of feeling words to change yourself?
If you were making a product to sell, why would you want to know what activities...
If you were making a product to sell, why would you want to know what activities are driving your overhead costs? Give a short example.
. What determines AVC? Explain what AVC depends on. Why would a firm want to know...
. What determines AVC? Explain what AVC depends on. Why would a firm want to know AVC? Explain how a firm uses AVC. What determines MP? Explain what MP depends on. Why would a firm want to know MP? Explain how a firm uses MP. What determines ɳ? Why would a firm want to know ɳ? Explain how a firm uses ɳ.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT