Question

what is the output values printed by the following code? You need to explain step by step how each printed value is calculate

int SampleMethod() { int j = 10; cout << j*3 <<endl; increase(); return j + 3; } void increase() { m = m + last digit of your

Id: 40100885

in c++

output text please

thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;

int m = 0;
void SampleMethod(int);
int SampleMethod();
void increase();

int main()
{
  int j=9;
  SampleMethod(j);
  cout << j <<endl;
  return 0;
}

// This function can not return any value because the return type is void
void SampleMethod(int j){
  if(j%2 == 1)
    cout << SampleMethod() << endl;   //print the value return by SampleMethod()
  else
    cout << j << " ";
  m = m + 2;
  cout << m << endl;
  j = j+1;
}

// This function return the value because the return type is int
int SampleMethod(){
  int j=10;
  cout << j*3 <<endl;   // it print 30
  increase();   // call the increase() function
  return j + 3;
}

void increase(){
  m = m + 5;
}

Output :-
30
13
7
9

Explanation:-

Execution is starts from main method. In main method j = 9 then we call SampleMethod( 9 ) ; function  
In SampleMethod(int j) check if( 9 % 2 == 1 ) is true it means that cout << SampleMethod() << endl; statement is executed and the value return by SampleMethod() is printed.
In SampleMethod() j = 10 ; cout << j*3 <<endl; means 30 is printed and after that increase() function is call.
In increase() m = m + last digit of your student id ; and the last digit of your student id = 5 because  Id: 40100885 given so m = 5;
After that in SampleMethod() last statement return j + 3; is executed , so it will return 13 to SampleMethod(int j) and
With the help of this statement cout << SampleMethod() << endl; 13 is printed.
After that In SampleMethod(int j) this statement m = m + second digit of your student number + 2; is executed and the value of second digit of your student number is 0 from Id: 40100885 and m = 5+2=7 and 7 is printed with the help of cout << m << endl;

After executing the SampleMethod(j) in main method , the statement cout << j <<endl; is executed and 9 is printed.

So the output is :-
30
13
7
9

Add a comment
Know the answer?
Add Answer to:
Id: 40100885 in c++ output text please thanks! what is the output values printed by the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT