Sams Teach Yourself C in 21 Days

(singke) #1
The C++ Programming Language 663

BD2


Quiz ..............................................................................................................



  1. What C++ object is available for printing?

  2. When should you use printf()in a C++ program?

  3. What values can be stored in the booldata type?

  4. What is the difference between declaring variables in C++ versus C?

  5. What operator(s) are available in C++ that are not available in C?

  6. What is the difference between using default values and using function overload-
    ing?

  7. Which of the following function declarations can be overlaid with each other?
    int triangle( int angle, int side1, int side2);
    int triangle(int side1, int side2, int side 3);
    int triangle(int side1, int side 2, int angle);

  8. Declare a function called triangle that receives three parameters:side1,side2, and
    side3. Each of these should be of type int. Set each of the sides to have a default
    value of 0.

  9. True or False: An inline function is a function that is replicated into the code
    within a listing.


Exercises ........................................................................................................



  1. Write a program that calculates the area of a box. Allow the user to enter the
    height, width, and length of the box.

  2. Modify the program in exercise 1 to calculate the cost of shipping the box. Assume
    that the cost is based solely on the number of cubic units of the box. If the box is
    under 100 cubic units, the cost is $5. If it is over 100 and less than 1000 units, it is
    $10. If it is over 1000 units, it is $20. Create the function to use a default value of
    $20.

  3. Specify the function that calculates the area of the box to be inline.


37 448201x-Bonus2 8/13/02 11:18 AM Page 663

Free download pdf