Pre-Lab Assignment: Lab 3

  1. Do exercise #1 from the take-home handout.

  2. Do exercise #2 from the take-home handout.

  3. Do exercise #3 from the take-home handout.

  4. Trace the execution of the following program if the input stream contains the integers 10, 8, 6, 9, 3, 5, 4, 7. Show the contents of the variables in the main program and in the function during its execution. Show what would be printed.
         #include <iostream>
         using namespace std;
    
         int mystery (int num1, int num2);
    
         int main ()
         {
            const double pi = 3.14159;
            int one, two, three, four; // four integer variables
    
            cout << "Enter four numbers: ";
            cin >> one >> two >> three >> four;
    
            one = mystery (one, two);
    
            cout << "One: " << one << " Two: " << two  << endl;
       
            two = mystery (three, four);
    
            cout << "Two: " << two << " Three: " << three << " Four: " << four << endl;
    
            return 0;
         }
    
         int mystery (int num1, int num2)
         {
            int num3;
    
            cout << "Enter two more numbers: ";
            cin >> num2 >> num3;
    
            return num1 + num2 + num3;
         }