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

Need help with these C++ programs: Part 2: What is output by the following? Assu

ID: 3730987 • Letter: N

Question

Need help with these C++ programs:

Part 2:

What is output by the following? Assume the necessary header files are included.

1. void f1(void);

   void f2(void);

void main(void) {

cout << 'A';

f1();

f2();

}

void f1(void) {

f2();

cout << 'B';

}

void f2(void) {

cout << 'C';

}

2. void f1(int);

   void f2(int, int);

void main(void) {

int x=5, y=2;

f1(x+y);

cout << endl << x << "+" << y << "=";

f2(x, y);

cout << endl;

}

void f1(int a) {

cout << a + 3 << " = ";

f2(a, 3);

}

void f2(int b, int c) {

cout << b + c;

}

3. int f1(int, int);

   bool f2(int, int);

void main(void) {

int x=5, y=2;

cout << f1(x, y) << endl;

if(f2(5, x))

     cout << "<=";

else

     cout << ">";

}

int f1(int a, int b) {

   return a + b;

}

bool f2(int b, int c) {

   if(b < c)

     return true;

   else if (b > c)

      return false;

   return true;

}

4. int f1(int, int);

void main(void) {

   int x=2, y=3;

   cout << f1(x, y);

}

int f1(int a, int b) {

   int i, j, cnt=0;

   for(i=1; i<=a; i++)    {

     for(j=1; j<=b; j++)    {

        cout << "*";

        cnt++;

      }

     cout << endl;

    }

   return cnt;

}

Explanation / Answer


Answers:
1.
void f1(void);
void f2(void);
void main(void)
{
cout << 'A';
f1();
f2();
}
void f1(void)
{
f2();
cout << 'B';
}
void f2(void)
{
cout << 'C';
}
Output:ACBC


Actually First A will be Printed in the Main Function. why because Every Program Execution should Start with Main Program
Inside Main Function Called two Sub-Functions F1() and F2().
First call F1(),Inside F1() Again we called F2() function So C Will be Printed.
after that B will be Printed and Again Function f2() is called. so C will be Printed again.

2.
void f1(int);
void f2(int, int);
void main(void)
{
int x=5, y=2;
f1(x+y);
cout << endl << x << "+" << y << "=";
f2(x, y);
cout << endl;
}
void f1(int a)
{
cout << a + 3 << " = ";
f2(a, 3);
}
void f2(int b, int c)
{
cout << b + c;
}

Output:-

10 = 10
5+2=7


3.
int f1(int, int);
bool f2(int, int);
int main(void)
{
int x=5, y=2;
cout << f1(x, y) << endl;
if(f2(5, x))
cout << "<=";
else
cout << ">";
}
int f1(int a, int b)
{
return a + b;
}
bool f2(int b, int c)
{
if(b < c)
return true;
else if (b > c)
return false;
return true;
}


Output:
7
<=


4.  
void main(void)
{
int x=2, y=3;
cout << f1(x, y);
}
int f1(int a, int b)
{
int i, j, cnt=0;
for(i=1; i<=a; i++)   
{
for(j=1; j<=b; j++)   
{
cout << "*";
cnt++;
}
cout << endl;
}
return cnt;
}

Output:
***
***
6

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote