Writing Functions that Require Multiple Parameters Summary In this lab, you comp
ID: 3803768 • Letter: W
Question
Writing Functions that Require Multiple Parameters
Summary
In this lab, you complete a partially written C++ program that includes a function requiring multiple parameters (arguments). The program prompts the user for two numeric values. Both values should be passed to functions named sum(), difference(), and product(). The functions compute the sum of the two values, the difference between the two values, and the product of the two values. Each function should perform the appropriate computation and display the results. The source code file provided for this lab includes the variable declarations and the input statements. Comments are included in the file to help you write the remainder of the program.
Instructions
Write the C++ statements as indicated by the comments.
Execute the program by clicking the "Run Code" button at the bottom of the screen.
___________________________
// Computation.cpp - This program calculates sum, difference, and product of two values.
// Input: Interactive
// Output: Sum, difference, and product of two values.
#include <iostream>
#include <string>
void calculateSum(double, double);
void calculateDifference(double, double);
void calculateProduct(double, double);
using namespace std;
int main()
{
double value1;
double value2;
cout << "Enter first numeric value: ";
cin >> value1;
cout << "Enter second numeric value: ";
cin >> value2;
// Call calculateSum
// Call calculateDifference
// Call calculateProduct
return 0;
} // End of main() function
// Write calculateSum function here
// Write calculateDifference function here
// Write calculateProduct function here
Explanation / Answer
Program:-
#include <iostream>
#include <string>
void calculateSum(double, double);
void calculateDifference(double, double);
void calculateProduct(double, double);
using namespace std;
int main()
{
double value1;
double value2;
cout << "Enter first numeric value: ";
cin >> value1;
cout << "Enter second numeric value: ";
cin >> value2;
calculateSum(value1, value2);// Calling calculateSum
calculateDifference(value1, value2);// Calling calculateDifference
calculateProduct(value1, value2);// Calling calculateProduct
return 0;
} // End of main() function
void calculateSum(double a, double b)// Writing calculateSum function
{
double sum;
sum=a+b;
cout<<"The Sum is :"<<sum<<endl;
}
void calculateDifference(double a, double b)// Writing calculateDifference function
{
double dif;
dif=a-b;
cout<<"The Difference is :"<<dif<<endl;
}
void calculateProduct(double a, double b)// Writing calculateProduct function
{
double mul;
mul=a*b;
cout<<"The Product is :"<<mul<<endl;
}
Output:-
Enter first numeric value: 546
Enter second numeric value: 985
The Sum is :1531
The Difference is :-439
The Product is :537810
Process exited normally.
Press any key to continue . . .
Enter first numeric value: 95
Enter second numeric value: 12
The Sum is :107
The Difference is :83
The Product is :1140
Process exited normally.
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.