home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch12 / default.cpp < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  44 lines

  1. //             default.cpp
  2. //
  3. // Synopsis  - Prompts for and accepts input of the price of an 
  4. //             item and displays the price of a case of items.
  5. //
  6. // Objective - To illustrate default values for function 
  7. //             parameters.
  8.  
  9. // Include Files
  10. #include <iostream.h>
  11.  
  12. // Function Prototypes
  13. double case_price( double item_cost, int case_size = 12 );  // Note 1
  14. // PRECONDITION:  item_cost is the cost of a single item. 
  15. //                case_size is the number of items in a case.
  16. //
  17. // POSTCONDITION: The function returns the price of a case of 
  18. //                case_size items that cost item_cost each
  19.  
  20. int main()
  21. {
  22.     cout << "The price of a case of items.\n"
  23.          << " ----------------------------\n\n";
  24.     cout << "Enter the price of a single item now: $ ";
  25.     double price;                                           // Note 2
  26.     cin >> price;
  27.  
  28.     cout << "If the case consists of 12 items, "
  29.          << "the case price will be $ "
  30.          << case_price( price ) << endl << endl;            // Note 3
  31.  
  32.     cout << "If the case consists of 24 items, "
  33.          << "the case price will be $ "
  34.          << case_price( price, 24 ) << endl;                // Note 4
  35.     return 0;
  36. }
  37.  
  38. /**************************** case_price ***************************/
  39.  
  40. double case_price( double item_cost, int case_size )        // Note 5
  41. {
  42.     return (item_cost * case_size);
  43. }
  44.