Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ For the following code segment, write out what is printed to the screen. Sho

ID: 3800738 • Letter: C

Question

C++

For the following code segment, write out what is printed to the screen. Show the displayed output precisely by using the following rules: Write one character per box. Skip a box to indicate the presence of a blank space in the output. Skip a row to indicate the presence of a blank line in the output. #include using namespace std; void sum (int&); int main () {int add = 4; Sum (add); Sum (add); Sum (add); Sum (add); return 0;} void Sum (int & add) static int sum = 0; static int j = 1; sum sum + add; cout

Explanation / Answer

first add(4 ) is called then in add function

sum=0+4=4

so j=1 and sum=4

after function j=2 add=3;

again sum(3) is called

so sum=4+3=7

j=2 sum=7

now j=3 and add=2 after the functiom

again add(2) is called

then sum=7+2=9

now j=4 and add=1 after the function

now add(1) is called

then sum=9+1=10

this is the output

1-4

2-7

3-9

4-10

1 - 4 2 - 7 3 - 9 4 - 10