Write a C++ program that uses user-defined functions to read three integer numbe
ID: 3551172 • Letter: W
Question
Write a C++ program that uses user-defined functions to read three integer numbers from the user,
compute the summation, difference, and product of these numbers, and print the results on the
screen.
Use only void functions (that pass parameters by value and reference, as needed). In particular, use
seven separate functions to do the following:
1. Prompt the user to enter three integer numbers. Use an appropriate message to ask the user to
enter the numbers.
2. Compute the summation of the numbers.
3. Compute the difference of the numbers.
4. Compute the product of the numbers.
5. Print the summation of the numbers. Use an appropriate message to indicate that the result is an
addition.
6. Print the difference of the numbers. Use an appropriate message to indicate that the result is a
subtraction.
7. Print the product of the numbers. Use an appropriate message to indicate that the result is a
multiplication.
All the above seven user-defined functions must be called in the main function. The source code
of your C++ program .cpp should be saved as lastname_firstname_pa3.cpp.
Explanation / Answer
#include<iostream>
using namespace std;
void getInput(int &a,int &b,int &c){
cout<<"Enter three integers: ";
cin>>a>>b>>c;
}
void getSum(int &sum,int &a,int &b,int &c){
sum = a+b+c;
}
void getDiff(int &d,int &a,int &b,int &c){
d = a-b-c;
}
void getProduct(int &p,int &a,int &b,int &c){
p = a*b*c;
}
void printSum(int a){
cout<<"Sum is: "<<a<<endl;
}
void printDiff(int a){
cout<<"Difference is: "<<a<<endl;
}
void printProd(int a){
cout<<"Product is: "<<a<<endl;
}
int main(){
int a,b,c,sum,diff,prod;
getInput(a,b,c);
getSum(sum,a,b,c);
getDiff(diff,a,b,c);
getProduct(prod,a,b,c);
printSum(sum);
printDiff(diff);
printProd(prod);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.