Name_______________________ Login___________________SID________

 

CS 010: Introduction to Computer Science I

Quiz 5: 10 minutes

 

            Use the following function headers for the next 4 questions

 

                                    void func1(int num1, int& num2)

                                    int func2(string str, int num)

 

  1. Which statement(s) has an error?

func1(10, 5);                        //Statement 1

cout << func2(“abc”, 20);   //Statement 2

 

a.      Statement 1

b.      Statement 2

c.      Statements 1 and 2

d.      No errors in either statement

 

  1. Which statement(s) has an error provided n1 and n2 are int variables that have been declared and initialized?

cout << func1(n1, n2);               //Statement 1

cout << func2(“abc”, n1);            //Statement 2

 

a.      Statement 1

b.      Statement 2

c.      Statements 1 and 2

d.      No errors in either statement

 

  1. Which statement(s) has an error provided n1 and n2 are int variables that have been declared and initializes?

func1(10, n1);                                    //Statement 1

cout << func2(10, “abc”);            //Statement 2

 

a.      Statement 1

b.      Statement 2

c.      Statements 1 and 2

d.      No errors in either statement

 

  1. Which statement(s) has an error provided n1 is an int variable that has been declared and initialized?

func1(func2(“abc”, 20), n1);

cout << func2(“abc”, func1(10, n1));

 

a.      Statement 1

b.      Statement 2

c.      Statements 1 and 2

d.      No errors in either statement

  1. Out of the following function headers, which is the BEST choice for a function that just reads in 2 integers from the user and “passes” them back to where the function was invoked (called)?

 

    1. void get_inputs(int& input1, int& input2)
    2. void get_inputs(int input1, int input2)
    3. int get_inputs(int input1, int input2)
    4. int get_inputs(int& input1, int& input2)
    5. int get_inputs()
    6. void get_inputs()

 

  1. Out of the following function headers, which is the BEST choice for a function that returns the value of the largest of 2 integers passed in as parameters?

 

    1. void max(int& first, int& second)
    2. void max(int first, int second)
    3. int max(int first, int second)
    4. int max(int& first, int& second)
    5. int max()
    6. void max()

 

  1. It is a syntax error to have a return statement in a void function (a function that has the return type of void).
    1. TRUE
    2. FALSE

 


Use the following function definitions to answer the next 3 questions

 

void func1(int& x)

{

      x += 50;

      return;

}

 

int func2(int y)

{

      y += 50;

      func1(y);

      return y;

}

 

  1. What is output by the following statements?

int a = 50;

func1(a);

cout << a;

    1. 0
    2. 50
    3. 100
    4. 150
    5. There is a syntax error in these statements
    6. None of the above

 

  1. What is output by the following statements?

                                    int a = 50;

                                    int b = func2(a);

                                    cout << a << “ “ << b;

 

    1. 50 150
    2. 100 100
    3. 50 100
    4. 150 150
    5. There is a syntax error in these statements
    6. None of the above

 

  1.  What is output by the following statement?

cout << func2(50);

 

    1. 0
    2. 50
    3. 100
    4. 150
    5. There is a syntax error in this statement
    6. None of the above