167k views
0 votes
Exercise Two: (6.4 Sending data into a Function, function prototype) Ask the user to enter 3 numbers inside the main function. Pass these 3 numbers to the function findSum, findMin, and findMax. Here is the skeleton of the main function for better understanding. Do not change main(). int main() int fn, sn, tn; cout<<"Enter first number:"; cin>>fn; cout<<"Enter second number:"; cin>>n; cout<<"Enter third number: "; cin>>tn; findSum(fn, sn, tn); findMin(fn, sn, tn); findMax(fn, sn, tn); return; }

Sample Output: (Numbers in red are ente Enter first number: 3 Enter second number: 9 Enter third number: 1 = Sum = 13 Maximum Number 9 Minimum Number = 1 = Note: • Do not change the main function. • must define the function findMax, findMin, findSum after the main function. For that you need to write the function prototype before the main. • Assume, not two numbers are same. Feel free to design your function output your way.

User BCDeWitt
by
8.2k points

1 Answer

5 votes

Final answer:

The task requires creating function prototypes and definitions for findSum, findMin, and findMax to work with the provided main function. These functions will output the sum, minimum, and maximum of three entered numbers.

Step-by-step explanation:

Defining findSum, findMin, and findMax Functions

To assist the student, we will define three functions that operate on the input numbers: findSum, findMin, and findMax. First, function prototypes have to be declared before the main function. Then, the functions themselves need to be defined after the main function.

The findSum function will calculate the sum of the three numbers, findMin will determine the smallest number, and findMax will identify the largest number. As the main function cannot be changed according to the exercise rules, we make sure the functions conform to the main function's calls.

// Function prototypes
void findSum(int a, int b, int c);
void findMin(int a, int b, int c);
void findMax(int a, int b, int c);

// Function definitions
void findSum(int a, int b, int c) {
int sum = a + b + c;
cout << "Sum = " << sum << endl;
}

void findMin(int a, int b, int c) {
int min = (a < b) ? (a < c ? a : c) : (b < c ? b : c);
cout << "Minimum Number = " << min << endl;
}

void findMax(int a, int b, int c) {
int max = (a > b) ? (a > c ? a : c) : (b > c ? b : c);
cout << "Maximum Number = " << max << endl;
}

User Shelman
by
6.9k points