Name_______________________ Login___________________SID________

 

CS 010: Introduction to Computer Science I

Quiz 6: 10 minutes

 

Use the following function headers for the next 4 questions.

      void func1(int x)

      void func2(int &x)

 

Assuming there is an integer called num, are the following statements valid?

 

  1. func2(25);
    1. TRUE
    2. FALSE

 

  1. func1(num*20+3);
    1. TRUE
    2. FALSE

 

  1. func1(rand()%100+1);
    1. TRUE
    2. FALSE

 

  1. func2(num);
    1. TRUE
    2. FALSE

 

 

Specify the best passing technique for the following parameters.

  1. double x = slope(myline);
    1. Pass-by-value
    2. Pass-by-reference

 

  1. scale_rectangle(length, width, scale_amount);                // Specify for the parameter length
    1. Pass-by-value
    2. Pass-by-reference

 

  1. change_name(boss);
    1. Pass-by-value
    2. Pass-by-reference

 

 

  1. Which of the following statements is NOT true?
    1. A non-void function must have a return statement.
    2. The return statement resumes execution in the main program.
    3. A function can have more than one return statement.
    4. It is legal to omit the return statement in a void function.
    5. Functions can only return one value.

Use the code below for the next 2 questions.

void f1(int &x)

{

            x = 100;

}

 

void f2(int &a, int b)

{

            a = a * b;

            b = 12;

            if (b < a)

            {

                        f1(b);

            }

            else

            {

                        f1(a);

            }

}

 

int main()

{

int num1 = 2;

int num2 = 4;

f2(num1, num2);

cout << num1 << “  “ << num2 << endl;           // OUTPUT 1

 

num1 = 4;

                                    num2 = 5;

                                    f2(num1, num2);

                                    cout << num1 << “    << num2 << endl;          // OUTPUT 2

 

            return 0;

}

 

  1. What will OUTPUT 1 print?
    1. 2  4
    2. 100  4
    3. 8 12
    4. 100  12
    5. None of the above

 

  1. What will OUTPUT 2 print?
    1. 20 5
    2. 20  100
    3. 4  5
    4. 20  12
    5. None of the above