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

#include<iostream> #include<stack> using namespace std; void f1(int x); int f2(i

ID: 3533069 • Letter: #

Question

#include<iostream>

#include<stack>

using namespace std;

void f1(int x);

int f2(int p);

int f3(int n);

int main(){

int a=5;

f1(a);

cout<<endl;

}

void f1(int x){

cout << f2( f3(x)); // B

}

int f2(int p){

int q=f3(p/2);

return 2*q;

}

int f3(int n)

{

    return n*n+1;

}



For each of the following, use a sequence of diagrams to trace

the action of the run-time stack with the specified

changes:

   

1. With a initialized to 5 instead of 3 and f1() replaced by

void fl(int x)

{

cout

Explanation / Answer

1)

#include<iostream>

#include<stack>

using namespace std;

void f1(int a);

int f2(int b);

int f3(int c);

void f1(int x)//error is here you have given fl not f1

{

int result=f3(x) + f2(x + 1);

cout<<result<<endl;

return;

}

int f2(int p){

int q=f3(p/2);

int dq=2*q;

return dq;

}

int f3(int n)

{

return (n*n+1);

}

int main(){

int a=5;

f1(a);

cout<<endl;

return 0;

}


2)

#include<iostream>

#include<stack>

using namespace std;

void f1(int a);

int f2(int b);

int f3(int c);

void f1(int x)

{

int res=f2( f3(x));

cout << res<<endl;

}

int f2(int p){

int q=f3(p/2);

int dq=2*q;

return dq;

}

int f3(int n)

{

return (n*n+1);

}

int main(){

int a=5;

f1(5);

cout<<endl;

return 0;

}