11. Function Tracing (20 points) Trace the following program. Show a work includ
ID: 3740312 • Letter: 1
Question
11. Function Tracing (20 points) Trace the following program. Show a work including labeled designated spaces. You should draw a box for each variable and show value updates. ll our work and the Show all of your boxes for user-defined functions, calculations, and the output in the #include using namespace std: void stewie(int, int &, int): void lois (int &, int, int &); void meg(int, int, int); int main( int numl 2, num2 4, num3 6, stewie (numl, num2, num3) meg (num3, numl, num2); lois (numl, num2, num3): meg (num3, numl, num2); system ("pause") return 0: void stewie(int a, int &b;, int c) int d; vanayl d=a+b+c; c=c+2; a=d%5; return; void lois(int su, int v, int w) u=u + v + w; Ww(v+1) meg (u, v, W) return; void meg(int x, int y, int z) coutExplanation / Answer
At the starting of main..
num1=2
num2=4
num3=6
when function stewie is called
num1 and num3 are passed by value but num2 is passed by reference.
num1 and num3 are catched by a and c respectivly and num2 is referenced as b.
at this point of execution:
a=2
b=4
c=6
all remaining variables remain the same.
d=2+4+6=12
b=4%2=0
c=6+2=8
a=12%5=2
num2=b=0
After execution of stewie function:
a=2
b=0
c=8
d=12
num2=0
num1=2
num3=6
now when meg is called:
num3, num1, num2 are passed by value and catched by x,y,z repectively
x=6
y=2
z=0
they will be printed as.
6
2
0
at the end of this function all the other variables remain constant.
now when lois is called:
num1, num3 are passed by reference and are referenced by u,w repectively.
num2 is passed by value and catched by v.
u=2
v=0
w=6
now when the fun lois executes:
u=2+0+6=8
w=6/(0+1)=6
now when meg is called inside lois:
u,v,w are passed by value and catched by x,y,z repectively
x=8
y=0
z=6
they will be printed as.
8
0
6
at the end of meg function all the other variables remain constant.
at the end of lois function:
num1=u=8
num3=v=6
all the other variables remain constant.
now when meg is called again in main:
num3, num1, num2 are passed by value and catched by x,y,z repectively
x=num3=6
y=num1=8
z=num2=0
they will be printed
6
8
0.
at the end of this function all the other variables remain constant.
system("pause") pauses the execution until u hit enter
Output:
6
2
0
8
0
6
6
8
0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.