Question: main foo bar heap int -10 i int & int -10 a int ? j j int & . int -30 int& b N int*

 main foo bar heap int -10 i int & int -10

a int ? j j int & . int -30 int& b

main foo bar heap int -10 i int & int -10 a int ? j j int & . int -30 int& b N int* int 5 Write a C++ program that declares variables and allocates memory to exactly match the diagram of memory above. The program must have exactly three functions named main, foo, and bar. Do not declare any variables or functions that are not shown in the diagram. The function main must initialize local variable i and declare local variable j, and then must call the function foo, storing the return value of foo in j. The function foo must have exactly two formal parameters named a and b. Write statements in foo so that the value of a (which initially gets the value -10) is doubled, the value of b is decremented by 1, and the local variable c is initialized to 5. The function foo must call the function bar, passing parameters as shown in the diagram. Finally, add a statement to foo so that the return value is the sum of a, b, and c; this value is returned to the calling scope. The function bar, which does not have a return value, must have exactly two formal parameters named x and y. It allocates an integer on the heap, initialized to -30, whose address it stores in local variable z. Add code to bar to add the values of x, y, and z together, and store the result in y. Immediately before bar terminates, add statements to output the final values of x, y, and z, labeled, one value per line. Immediately before foo returns, add statements to output the final values of a, b, and c, labeled, one value per line. Immediately before main returns, add statements to output the final values of i and j, labeled, one value per line. Any memory that your program allocates via the new operator must be correctly deallocated before the program ends. The function main must initialize local variable i and declare local variable j, and then must call the function foo, storing the return value of foo in j. The function foo must have exactly two formal parameters named a and b. Write statements in foo so that the value of a (which initially gets the value -10) is doubled, the value of b is decremented by 1, and the local variable c is initialized to 5. The function foo must call the function bar, passing parameters as shown in the diagram. Finally, add a statement to foo so that the return value is the sum of a, b, and c; this value is returned to the calling scope. The function bar, which does not have a return value, must have exactly two formal parameters named x and y. It allocates an integer on the heap, initialized to -30, whose address it stores in local variable z. Add code to bar to add the values of x, y, and z together, and store the result in y. Immediately before bar terminates, add statements to output the final values of x, y, and z, labeled, one value per line. Immediately before foo returns, add statements to output the final values of a, b, and c, labeled, one value per line. Immediately before main returns, add statements to output the final values of i and j, labeled, one value per line. Any memory that your program allocates via the new operator must be correctly deallocated before the program ends. A run of your program should produce output that looks exactly like this, except these values are not necessarily correct: $ - /program X: 12 y: 34 z: 56 a: 78 b: 91 C: 23 i: 45 j: 67 A significant part of this assignment is for you to verify that the values printed by your program are correct. In no case should your program print a hexadecimal address, only values that would be useful to a user. For this assignment, do not worry about declaring constants for magic numbers or about single-letter variable names. Hard-code the indicated values and use the variable names I have indicated. Also, for this assignment, do not write any Doxygen function documentation (but do put your name at the top of the program.) Otherwise, make sure your code adheres to the course coding standards. Of particular note: spaces on both sides of binary operators and after commas, no spaces between a unary operator and its argument, make sure output is terminated with a newline, and that no tab characters are in the source code. bisedobbie Banment

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!