c++ Question 1 Consider the following program: #include iostream using namespace
ID: 3724188 • Letter: C
Question
c++
Question 1
Consider the following program:
#include iostream
using namespace std;
int addition(int, int);
int subtraction(int, int);
void directions();
void printResult(int, int, int, char);
int main ()
{
int x,y,r;
directions();
cout << "Please enter the first integer: "<<;
cin >> x;
cout << "Please enter the second integer: ";
cin >> y;
r = addition(x,y);
printResult(x,y,r,’+’);
r = subtraction(x,y);
printResult(x,y,r,’-’);
system("pause");
return 0;
}
int addition(int a, int b)
{
int r;
r=a+b;
return r;
}
int subtraction(int a, int b)
{
int r;
r=a-b;
return r;
}
void directions()
{
cout << ********************************************************" << endl
<< "Hello!" << endl
<< "This Program asks the user for two integers, then prints the sum and difference" << endl
<< "****************************************************** << endl << endl;
}
void printResult(int a, int b, int result, string operation)
{
cout << a < " " << operation << " " << b << " = " << result << endl;
}
1.1) How many functions are defined in this program, including the main() function
1.2) Give the prototype of each function.
1.3) Give the arguments of each function.
1.4) Give the parameters of each function.
1.5) Compile the program and fix all errors that may occur. Complete test plan. Run the program and fill in the remainder of your test plan.
Explanation / Answer
here are the answers..
==============================================================
Ans:1
There are four+one = five function which are defined in the program.
int addition(int, int);
int subtraction(int, int);
void directions();
void printResult(int, int, int, char);
and main() function.
===============================================================
Ans:2
Each function protypes are follwing...
int addition(int, int);
int subtraction(int, int);
void directions();
void printResult(int, int, int, char);
int main()
===============================================================
Ans:3
Argument of each function is specified in front....
x, y, r, +, - are the arguments passed to function in the main program. Arguments are the actual values passed to function.
=============================================================
Ans:4
parameters are the formal value passed to functions..
int addition(int a, int b) a, b are parameters passed.
int subtraction(int a, int b) a, b are parameters passed.
void printResult(int a, int b, int result, string operation) a, b, result, operations are the parameters.
void directions() (no paremeter is passed.)
int main () (no paremeter is passed.)
===============================================================
here is the complete working code..
===============================================================
Program:
===============================================================
#include <iostream>
#include<string.h>
using namespace std;
int addition(int, int);
int subtraction(int, int);
void directions();
void printResult(int, int, int, char);
int main()
{
int x,y,r;
directions();
cout << "Please enter the first integer: ";
cin >> x;
cout << "Please enter the second integer: ";
cin >> y;
r = addition(x,y);
printResult(x,y,r,'+');
r = subtraction(x,y);
printResult(x,y,r,'-');
system("pause");
return 0;
}
int addition(int a, int b)
{
int r;
r=a+b;
return r;
}
int subtraction(int a, int b)
{
int r;
r=a-b;
return r;
}
void directions()
{
cout <<"********************************************************" << endl;
cout<< "Hello!" << endl;
cout<< "This Program asks the user for two integers, then prints the sum and difference" << endl;
cout<< "****************************************************** "<< endl;
}
void printResult(int a, int b, int result, char operation)
{
cout << a << " " << operation << " " << b << " = " << result << endl;
}
===============================================================
Kindly Check and Verify Thanks..!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.