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
  • Using C++, fix the following code so that (1) Change the student array storage part so...

    Using C++, fix the following code so that (1) Change the student array storage part so that the data is loaded from a file "students.txt". Use an appropriate data    termination flag. (2) Sort the student array in ascending order of GPA using insertion sort. Print the sorted array (3) Sort the student array in ascending order of ID using insertion sort. Print the sorted array (4) Illustrate Binary search for a particular ID that would be found and one...

  • 6. Please provide step by step and concepts explanation. Thank you ! What is the output...

    6. Please provide step by step and concepts explanation. Thank you ! What is the output of the following program? #include <iostream> using namespace std; int fun (int p 2, int q = 3) return p+ qi int main (void) cout < fun (O +fun (1) + fun (1, 2) <<endl; return 0; 6 O 8 10 O 12

  • C++ output 6) What is the exact output of the following program? #include <iostream> using namespace...

    C++ output 6) What is the exact output of the following program? #include <iostream> using namespace stdi void zolo(int &a, int sb) int main int x = 5, y =8; zolo(x,y)i cout << "x " << x << endl ; cout << "y = "" << y << endl ; return o: void zolo(int &a, int &b) int v1 = b + a; ' int v2 = b-a; 3 a=v1;13

  • Please help! Studying for my c++ test! What does the following code produce? include <iostream>   ...

    Please help! Studying for my c++ test! What does the following code produce? include <iostream>    using namespace std; void my_function(int n); void main() {     my_function(546); } void my_function(int n) {     if (n < 10)         cout << n << endl;     else     {         my_function(n/10);         cout << (n%10) << endl;     } } What is the output of the following code?                   int j=32, k=5, r;                   r = j ^ k;                   cout << r...

  • Question 28 What is the output of the following program? Assume code is correct. #include <iostream>...

    Question 28 What is the output of the following program? Assume code is correct. #include <iostream> using namespace std; int main() { int i = 1,j,x = 5, y = 4; while (i <= y) { for (j = 0; j <= y2; j++) cout << 'Z'; cout << endl; i=i+1; } return 0; 3 B IV AA-I E333 X X, B, GT 12pt Paragraph

  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • Update your first program to dynamically allocate the item ID and GPA arrays. The number of...

    Update your first program to dynamically allocate the item ID and GPA arrays. The number of items will be the first number in the updated “student2.txt” data file. A sample file is shown below: 3 1827356 3.75 9271837 2.93 3829174 3.14 Your program should read the first number in the file, then dynamically allocate the arrays, then read the data from the file and process it as before. You’ll need to define the array pointers in main and pass them...

  • I know I'm on the right path, but don't know where to continue from here. This is a C++ assignmen...

    I know I'm on the right path, but don't know where to continue from here. This is a C++ assignment Your job is to write that will display a calendar for any given month of a given year. The user will need to type the number of the month as an integer from 1 to 12 (1 is for January, etc.), and the year as a 4-digit integer. This assignment simply requires that your program make use of more than...

  • Subject: Object Oriented Programming (OOP) Please kindly solve the above two questions as soon as possible...

    Subject: Object Oriented Programming (OOP) Please kindly solve the above two questions as soon as possible would be really grateful to a quick solution. would give a thumbs up. Thank you! Q3: Question # 3 [20] Will the following code compile? If it does not, state the errors. If it does compile, write the output. //Function.cpp #include <iostream> using namespace std; void printData (long i) cout<<"In long print Data "«<i<<endl; } void printData(int i) cout<<"In int printData "<<i<<endl; ) void...

  • Give the output of the following C++ program and explain your reasoning: #include <iostream> using namespace...

    Give the output of the following C++ program and explain your reasoning: #include <iostream> using namespace std; int gcd( int , int ); //Function prototype int main() { int a = 105; int b = 30; cout << “The GCD of “ << a << “ and “ << b << “ is “ << gcd(a,b) << endl; return 0; } int gcd(int a, int b) { if ( b == 0 ) return a; else return gcd(b,a%b); }

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