Question

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 << "\nF = " << F << endl;

   cout << "G = " << G << "\nH = " << H << endl;

   cout << "W = " << W << "\nX = " << X << endl;

   return 0;

}

void F1(int E,int F,int G,int& H)

{ E=4;

    F=3;

    G+=E;

    H+=F;

}

void F2(int W,int& X,int& Y,int& Z)

{ W=8;

    X=7;

    Y+=W;

    Z+=X;

}

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

Please find below the explanation:

  1. Intitial Values: E = 1, F = 2, G = 3, H = 4, W = 5, X = 6;
  2. Function F1:
    1. Function Call : F1(E, F, G, H);
    2. Function Defintion F1 :
    • void F1(int E, int F, int G, int& H) { // The Values of E, F, G will not change as only value is passed. Where as for H, address of H(&H) is referenced therefore the values will be reflected in main()
      E = 4; // In F1(): E = 4, In main(): E = 1  
      F = 3; // In F1(): F = 3, In main(): F = 2  
      G += E;   // In F1(): G = 3, In main(): G = 3  
      H += F;   // In F1(): H = 3, In main(): H = H + F = 4 + 3 = 7
      }
  3. Current Values:  E = 1, F = 2, G = 3, H = 7, W = 5, X = 6;
  4. Function Defintion F1 :
    1. Function Call : F2(E, F, G, H);
    2. Function Defintion F2 :
      • void F2(int W, int& X, int& Y, int& Z) {
      • F2() W is main() E
      • F2() X is main() F
      • F2() Y is main() G
      • F2() X is main() H
      • // The Value of E will not change as only value is passed. Where as for F, G, H, address of F(&X), G(&Y), H(&Z) is referenced therefore the values will be reflected in main()
        W = 8; // In F2(): W = 8, In main(): E = 1
        X = 7;   // In F2(): X = 7, In main(): F = 7
        Y += W; // In F2(): Y = Y + W = 3 + 8 = 11, In main(): G = 11
        Z += X;   // In F2(): Z = Z + X = 7 + 7 = 14, In main(): H = 14
        }
  5. Final Values:  E = 1, F = 7, G = 11, H = 14, W = 5, X = 6;
Add a comment
Know the answer?
Add Answer to:
I know the right answers by using a compiler. However, can you please explain each step...
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
  • What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int &...

    What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int & x); int z = 10; void main() { char x = 'y'; int y = 5; int z = 100; y = DontPanic(z); cout << x << " " << y << " " << z << endl; } int DontPanic(int & x) { int * p; p = & z; x = (*p)++ + 1; cout << x << " " << *p...

  • How can I fix that ? Can you please explain clearly ? main.cpp 2 3 using...

    How can I fix that ? Can you please explain clearly ? main.cpp 2 3 using namespace 4. 5 int main() std; unsigned int x = 0b01101100; 8 9 10 12 13 14 15 16 17 18 19 20 21 unsigned int z = 0x12345678; unsigned int e 0x7; unsigned int w = 0x87654321; unsigned int =0x123; int 1; int 92; int Q3; int Q4; Q1=x&y; cout << bitset<8> (Q1) << endl; Q2=-(x| y); cout << bitset<8>(Q2) << endl; Q3=(z...

  • Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int);...

    Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?

  • 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...

  • Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and...

    Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and user_main.cpp. The programming language is C++. I will provide the Sample Test Driver Code as well as the codes given so far in text below. Sample Testing Driver Code: cs52::FlashDrive empty; cs52::FlashDrive drive1(10, 0, false); cs52::FlashDrive drive2(20, 0, false); drive1.plugIn(); drive1.formatDrive(); drive1.writeData(5); drive1.pullOut(); drive2.plugIn(); drive2.formatDrive(); drive2.writeData(2); drive2.pullOut(); cs52::FlashDrive combined = drive1 + drive2; // std::cout << "this drive's filled to " << combined.getUsed( )...

  • I have to type and explain in class each code in every detail filled with //...

    I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() {    int var1 = 20 ;    int var2 = 30 ;    int* ptr1 ;    int* ptr2 ;    int* temp ;    ptr1 = &var1 ;    ptr2 = &var2 ;    cout << *ptr1 << endl ;...

  • In this assignment you are required to complete a class for fractions. It stores the numerator...

    In this assignment you are required to complete a class for fractions. It stores the numerator and the denominator, with the lowest terms. It is able to communicate with iostreams by the operator << and >>. For more details, read the header file. //fraction.h #ifndef FRACTION_H #define FRACTION_H #include <iostream> class fraction { private: int _numerator, _denominator; int gcd(const int &, const int &) const; // If you don't need this method, just ignore it. void simp(); // To get...

  • 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...

  • #include <iostream> #include <cmath> using namespace std; int main() { int x; int y; int z;...

    #include <iostream> #include <cmath> using namespace std; int main() { int x; int y; int z; int r1; int r2; cin >> x; cin >> y; cin >> z; r1 = 4* pow(x,3)-5*pow(y,2)+3*z; r2 = r1+7*pow(x,3)-2*pow(y,2)+11*z; cout << "r1="; cout << 4* pow(x,3)-5*pow(y,2)+3*z; cout << endl; cout << "r2="; cout << r1+7*pow(x,3)-2*pow(y,2)+11*z; cout << endl; cout << "r3="; cout << r2-9*pow(x,3)+22*pow(y,2)-6*z; cout << endl; return 0; } 1-115 Your output r2-395 13-186 5:Compare output Output differs. See highlights below. -163...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

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