Request assistance in writing a C++ code for a void function that receives four
ID: 3656962 • Letter: R
Question
Request assistance in writing a C++ code for a void function that receives four int variables; the first two by value and the last two by reference. Name the formal parameters n1, n2, sum, and diff. The function should calculate the sum of the two variables passed by value and then store the result in the first variable passed by reference. It should also calculate the difference between the two variables passed by value and then store the result in the second variable passed by reference. When calculating the difference, subtract the contents of the n2 variable from the contents of the n1 variable. Name the function cal cSumAndDiff. Also write an appropiated function prototype for the cal cSumAndDiff function. In addition, write a statement that invokes the cal cSumAndDiff function, passing it the num1, num2, numSum, and numDiff variables.Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
void cSumAndDiff(int,int,int&,int&);
int main()
{int num1, num2, numSum,numDiff;
cout<<"Enter 1st number: ";
cin>>num1;
cout<<"Enter 2nd number: ";
cin>>num2;
cSumAndDiff(num1, num2, numSum,numDiff);
cout<<num1<<" + "<<num2<<" = "<<numSum<<endl;
cout<<num1<<" - "<<num2<<" = "<<numDiff<<endl;
system("pause");
return 0;
}
void cSumAndDiff(int n1,int n2,int& s,int& d)
{s=n1+n2;
d=n1-n2;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.