Question

Help c++ please 3 easy questions, that's why I put them together, not worth asking each...

Help c++ please

3 easy questions, that's why I put them together, not worth asking each one individually.

1) If test() were called 3 more times, what would be last line printed by test()?

2)

What is the output of the following code? (Note that there are no endl's, all output is on a single line)

int vol(int s);
int vol(int x, int y, int z=1);
int main()
{
   cout << vol(2) << "-";
   cout << vol(3, 2) << "-";
   cout << vol(3, 2, 4);
   return 0;
}
int vol(int s)
{
   return s * s * s;
}
int vol(int x, int y, int z)
{
   return x * y * z;
}

3)  

What is the output of the following code? (Note that there are no endl's, all output is on a single line)

void fun(int &a, int b, int &c);

int main()
{
   int a = 1;
   int b = 2;
   int c = 3;
   fun(a, b, c);
   cout << a << '-' << b << '-' << c << '-';
   fun(b, c, a);
   cout << a << '-' << b << '-' << c;
   return 0;
}
void fun(int &a, int b, int &c)
{
   a = a + 3;
   b = a * 4;
   c++;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer-

2- This program output is- 8-6-24. This program has 2 functions-first with one parameter and the second 3 parameters.

int vol(int s)

{

s*s*s;

}

This function is taking one value as one parameter and returning value is – multiply the value three times. When this function is calling value 2 is passing then it is taking and returning 8. That is the correct and after 8 it is printing ‘–‘ because there is print statement after calling function print ‘-‘ that’s why it is printing.

Next function is- int vol(int x, int y, int z=1). In this function, all three parameters are multiplying each together and returning the product.

In program. The second function is called with 2 parameters passing then it will this function. Parameters values are- 3,2. It is taking both values as x,y and z already initialized so it is multiplying all-3*2*1= 6 it is returning with dash because in printing statement dash is printing.

Next time also function is called with 3 parameters vol(3,2,4); It is taking values x,y,z now there is a value for z also so it will store in z=4 then it will multiply and return the product. 3*2*4=24

Output is- 8-6-24

3- This program has one function with 3 parameters, two’s are reference variables and one is actual parameters.

The program output is 4-2-4-5-5-4.

When a parameter is passed by value, a copy of the parameter is made. Therefore, changes made to the formal parameter by the called function have no effect on the corresponding actual parameter. Look at your program- there is a variable b is the actual parameter when we are changing in this variable there is no effect to b variable.

When a parameter is passed by reference, the conceptually actual parameter itself is passed( just given the name of the corresponding formal parameter. That’s why any changes made to the formal parameter do affect the actual parameter. In program 3 we can see reference variable changes their values.

1- I am confused about this one what you want, there is no code also. Just comment me in the comment box I'll provide your answer.

Add a comment
Know the answer?
Add Answer to:
Help c++ please 3 easy questions, that's why I put them together, not worth asking each...
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
  • 16 Points) Question 3 Write down the outputs of the following program into the provided table include <iostream> using namespace std; void fun I(int a); int fun2(int a, int b); int x-3: int...

    16 Points) Question 3 Write down the outputs of the following program into the provided table include <iostream> using namespace std; void fun I(int a); int fun2(int a, int b); int x-3: int main) int x-1,y 0,z-2; x-fun2(y,z); cout sx fun 1 (z); cout (#xtytz(endl; y-fun2(x,x); cout <exty+zscendl; system("pause"); void fun 1 (int a) int fun2(int a, int b) int static c2; return atx; 16 Points) Question 3 Write down the outputs of the following program into the provided table...

  • Id: 40100885 in c++ output text please thanks! what is the output values printed by the...

    Id: 40100885 in c++ output text please thanks! what is the output values printed by the following code? You need to explain step by step how each printed value is calculated. #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; w Y == void SampleMethod(int i) { if (j%2 1) cout << SampleMethod() <<endl; else cout << j << "...

  • (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0)...

    (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...

  • Why this C++ code output is 1 1 num is 3 Can u explain to me?...

    Why this C++ code output is 1 1 num is 3 Can u explain to me? Thank u code: #include using namespace std; void xFunction(int num) { do { if (num % 2!= 0) cout << num << " "; num--; } while (num >=1); cout << endl; } int main() { int num = 1; while (num <= 2) { xFunction(num); ++num; } cout << "num is " << num; return 0; }

  • Three is 3 questions please answer them all Question 1 int main(void) { int x =...

    Three is 3 questions please answer them all Question 1 int main(void) { int x = 10, y = 20; if (x == y); printf ("\n%d %d",x,y); } Output as you would see on the compiler: Question 2 int main(void) { int x = 3, y = 5; if (x == 3) printf ("\n%d",x); else ; printf("%d", y); return 0; Output as you would see on the compiler: Question 3 int main(void) { int x = 3; float y =...

  • 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

  • I know the right answers by using a compiler. However, can you please explain each step...

    I know the right answers by using a compiler. However, can you please explain each step and how you get the correct answer. Thank you in advance. Output: E = 1 F = 7 G = 11 H = 14 W = 5 X = 6 Problem 7 #include <iostream> #include <cmath> using namespace std; void F1(int,int,int,int&); void F2(int,int&,int&,int&); int main ( void ) { int E=1,F=2,G=3,H=4,W=5,X=6;    F1(E,F,G,H);    F2(E,F,G,H);    cout << "E = " << E <<...

  • Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void)...

    Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void) { x = x + 2; y = y + 4; } void bar(void) { int x = 10; y = y + 3; foo( ); cout << x << endl; cout << y << endl; } void baz(void) { int y = 7; bar( ); cout << y << endl; } void main( ) { baz( ); } What output does this program...

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • Use the code below to answer the questions that follow. Assume that all proper libraries and...

    Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid , write in the last digit of your SMC student ID. int foo(int a, int b) { //First int c = a+b; while(c>=3) c-=3; return c; } //------------------------------------ char foo(string a, int b) { //Second return a[b]; } //------------------------------------ string foo(int b, string...

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