1.
Hello
Goodbye
One more time:
Hello
End of program.
2. no
3.
No impact on program as return statement is optional in void function initialize_screen.
Program would compile.
Program would run.
Program would behave normally.
Return statement is optional in void function show_results.
No effect on program if return statement is missing.
Function celsius returns a value of double so the return statement is mandatory.
Program would not compile if return statement would be missing from celsius function.
4.
void function (int, int, int);
//Input three integers
//Output product of the three inputs
void main()
{
using namespace std;
int x, y, z;
cout << "Enter three integers & product will be output to screen.\n";
cin >> x
>> y
>> z;
}
void function (int a, int b, int c)
{
using namespace std;
cout << a*b*c;
}
5.
Microsoft Visual Studio 2010 compiles without errors void main() and int main().
No warnings or errors were experienced with int main() and having no return 0; statement in program.
6. Statement, since no values are returned expressions cannot be used.
7.
10 20 30
1 2 3
1 20 3
8. 5 5
9.
par1_value in function call = 111
par2_ref in function call = 222
n1 after function call = 1
n2 after function call = 2
10.
void zero_both( int& a, int& b )
{
a = 0;
b = 0;
}
11.
void add_tax( double tax_rate, double& cost )
{
cost = cost + (tax_rate * cost)
}
12.Yes, Yes.
13. No.
14. Yes.
15.
// Precondition two int will be given values
// Postcondition two int will be ordered from smaller to larger int
16.
// Precondition one number will be given a value
// Postcondition square root will be returned
17. Every function should be tested in a program in which every other function
in that program has already been fully tested and debugged.
18. A driver program is a minimal & temporary tool to test functions.
19. To test two cout statements I would put statements in main program then run it. If it works
put brackets around code & add function header & place appropriately in program. Then put function
call in main program, then run, and compare outputs.
20. I would write a program that requests from user tax_rate & cost then output calculation to screen.
Then run various inputs and compare results to known answers.
21. A stub is a simplified or partially incomplete function used for testing & filler for program outline.
22.
double rain_prob(double a, double b, double c)
{
return 1;
}
23. Put assert(z==0); before expression that is being tested.
24. A separate utility program that allows programmer to stop program at any time or step through execution of code
one step at a time.
25. keep an open mind, check common errors, localize error, use second set of eyes, use debugger