C++ Homework to be done
1. show the hex addresses and variable values after the statements have been executed. (All pointers are 4 bytes!. First by of the memory starts at xFF30)
|
g_ptr |
f_ptr |
b_ptr |
g |
f |
e |
d |
c |
b |
a |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xFF30
int main()
{
float a= 15.1, b, c;
int d = 4, e = 18, f,g;
float *b_ptr;
int *f_ptr, *g_ptr;
b_ptr = &b;
f_ptr = &f;
g_ptr = &g
c = e%d + e/d;
*f_ptr = 2.0*a - 1.0;
*b_ptr = 7/9*(a*c + d);
}
2. Write a complete C++ program that calculates the number of paint cans needed to paint a room including its ceiling. Program should ask the user for hight, length, width of the room, in feet. Program should also ask for the number of square feet a can of paint will cover (i.e., enough to paint). Assume that the room has no windows or doors.
a) Variables that program asks user for input values for should all be declared in the main.
b) The program should have a function called askForInputs() that asks for input from the user and should update the variables declared in the main() using indirection by passing pointers from main() to askForInputs() .
c) After reading input values from user, main() should pass the values to another function called calcNumPaintCans() that takes as input the values of hight, width, length, and numSqrFtPerCan and should return back to main() the total number of cans the user should buy.
d) Create a function called printInfo() that takes “ hight, width, length, numSqrFtPerCan, numPaintCans” and should write an output that states:
--------------------------------------------------------------------------
To paint the walls and ceiling of a room that has a length of … ft, width of … ft, height of … ft, where each can of paint covers … sft, you would need to buy … cans of paint.
---------------------------------------------------------------------------