C++ Ch 5 Quiz - Functions

22 Questions | Attempts: 429
Share

SettingsSettingsSettings
C++ Ch 5 Quiz - Functions - Quiz

C++ is a programming tool widely used today. If you are a programmer and you are looking for ways to better yourself in this field, then this quiz will do just that. All the best as you attempt the quiz.


Questions and Answers
  • 1. 
    A void function can return any value   true or false?
    • A. 

      True

    • B. 

      False

  • 2. 
    The following is legal in a void function return; true or false?
    • A. 

      True

    • B. 

      False

  • 3. 
    In a function with call-by-reference parameters, any changes to the formal parameters will change the actual arguments passed to the function. true or false?
    • A. 

      True

    • B. 

      False

  • 4. 
    It is acceptable to have both call-by-value and call-by-reference parameters in the same function declaration. true or false?
    • A. 

      True

    • B. 

      False

  • 5. 
    A stub is a function that is completely defined and well tested true or false?
    • A. 

      True

    • B. 

      False

  • 6. 
    Which of the following is a legal call to the displayOutput function? void displayOutput(int total);
    • A. 

      Void displayOutput(myTotal);

    • B. 

      DisplayOutput(int mytotal);

    • C. 

      DisplayOutput(myTotal);

    • D. 

      Cout

  • 7. 
    The precondition(s) for a function describe
    • A. 

      What is true after the function is executed

    • B. 

      What the function does

    • C. 

      How to call the function

    • D. 

      What must be true before the function executes

  • 8. 
    Which of the following is true for a void function?
    • A. 

      There cannot be a return statement.

    • B. 

      The value of void should be returned.

    • C. 

      The value of 0 should be returned.

    • D. 

      Nothing is returned

  • 9. 
    What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float& taxCost); float tax = 0.0, subTotal = 0.0; calculateCost(15, subTotal,tax); cout << "The cost for 15 items is " << subtotal << ", and the tax for " << subTotal << " is " << tax << endl; //end of fragment void calculateCost(int count, float& subTotal, float& taxCost) { if ( count < 10) { subTotal = count * 0.50; } else { subTotal = count * 0.20; } taxCost = 0.1 * subTotal; }
    • A. 

      The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;

    • B. 

      The cost for 15 items is 0.00, and the tax for 3.00 is 0.00;

    • C. 

      The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;

    • D. 

      The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;

  • 10. 
    What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float taxCost); float tax = 0.0, subtotal = 0.0; calculateCost(15, subtotal,tax); cout << "The cost for 15 items is " << subtotal << ", and the tax for " << subtotal << " is " << tax << endl; //end of fragment void calculateCost(int count, float& subTotal, float taxCost) { if ( count < 10) { subTotal = count * 0.50; } else { subTotal = count * 0.20; } taxCost = 0.1 * subTotal; }
    • A. 

      The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;

    • B. 

      The cost for 15 items is 0.00, and the tax for 3.00 is 0.00;

    • C. 

      The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;

    • D. 

      The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;

  • 11. 
    Which of the following function prototypes are not valid?
    • A. 

      Void doSomething(int& x, int y);

    • B. 

      Void doSomething( int& x, int& y);

    • C. 

      Void doSomething( int x, int y);

    • D. 

      All are valid

  • 12. 
    What is the value of choice after the following statements? void getChoice(int& par_choice, in par_count); int choice, count=3; getChoice(choice, count); void getChoice(int& par_choice, in par_count) { if(par_count<0) par_choice =0; if(par_count = 0) par_choice=-1; else par_choice=99; return; }
    • A. 

      3

    • B. 

      0

    • C. 

      -1

    • D. 

      99

  • 13. 
    If you were to write a function for displaying the cost of an item to the screen, which function prototype would be most appropriate?
    • A. 

      Void display();

    • B. 

      Void display(float myCost);

    • C. 

      Int display (float myCost);

    • D. 

      Float display();

  • 14. 
    Given the function definition void something ( int a, int& b ) { int c; c = a + 2; a = a * 3; b = c + a; } what is the output of the following code fragment that invokes something? (All variables are of type int.) r = 1; s = 2; t = 3; something(t, s); cout << r << ' ' << s << ' ' << t << endl;
    • A. 

      1 14 3

    • B. 

      1 10 3

    • C. 

      5 14 3

    • D. 

      1 14 9

    • E. 

      None

  • 15. 
    Given the following function declaration and local variable declarations, which of the following is not a correct function call? int myInt; float myFloat; char ch; void someFunction(int& first, float second, char third);
    • A. 

      SomeFunction(1, 2.0, ch);

    • B. 

      SomeFunction(myInt, myFloat, ch);

    • C. 

      SomeFunction(myInt, 2.0, 'c');

    • D. 

      SomeFunction(myInt, myFloat, '1');

  • 16. 
    In the following function, what is passed to the first parameter? void f1( int& value1, int value2); int x,y; f1(x,y);
    • A. 

      The value of x

    • B. 

      Nothing, it is a void function

    • C. 

      The value of y

    • D. 

      The variable x (or its memory location)

  • 17. 
    A simplified main program used to test functions is called
    • A. 

      A stub

    • B. 

      Abstraction

    • C. 

      Polymorphism

    • D. 

      A driver

  • 18. 
    Which of the following comments would be the best post-condition for this swap function void swap( int& left, int&right);
    • A. 

      //Postcondition: None

    • B. 

      //Postcondition: the values of left and right are exchanged.

    • C. 

      //Postcondition: left has the value of right

    • D. 

      //Postcondition: left and right are unchanged

  • 19. 
    What is wrong with the following code? int f1( int x, int y) { x = y * y; return x; int f2( float a, float& b) { if(a < b) b = a; else a=b; return 0.0; } }
    • A. 

      Neither function should return a value

    • B. 

      Function definitions may not be nested

    • C. 

      Both parameters to f2 should be pass-by reference

    • D. 

      In f2, a can not be assigned b.

    • E. 

      Nothing is wrong

  • 20. 
    Testing your program should be done
    • A. 

      As each function is developed

    • B. 

      At the end of the coding

    • C. 

      Only if there appear to be problems

    • D. 

      Only if your instructor requires it.

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.