home *** CD-ROM | disk | FTP | other *** search
/ Share Gallery 1 / share_gal_1.zip / share_gal_1 / ED / ED003A.ZIP / ANSWERS / CH07_1.CPP < prev    next >
Text File  |  1990-07-20  |  2KB  |  66 lines

  1.                               // Chapter 7 - Programming exercise 1
  2. #include "iostream.h"
  3. #include "vehicle.hpp"
  4. #include "car.hpp"
  5. #include "truck.hpp"
  6.  
  7.  
  8. main()
  9. {
  10. vehicle unicycle;
  11. vehicle bicycle;
  12.  
  13.    unicycle.initialize(1, 12.5);
  14.    cout << "The unicycle has " << 
  15.                                 unicycle.get_wheels() << " wheel.\n";
  16.    cout << "The unicycle's wheel loading is " << 
  17.          unicycle.wheel_loading() << " pounds on the single tire.\n";
  18.    cout << "The unicycle weighs " << 
  19.                              unicycle.get_weight() << " pounds.\n\n";
  20.  
  21.    bicycle.initialize(2, 38.0);
  22.    cout << "The bicycle has " << 
  23.                                 bicycle.get_wheels() << " wheels.\n";
  24.    cout << "The bicycle's wheel loading is " << 
  25.          bicycle.wheel_loading() << " pounds per tire.\n";
  26.    cout << "The bicycle weighs " << 
  27.                              bicycle.get_weight() << " pounds.\n\n";
  28.  
  29. car sedan;
  30.  
  31.    sedan.initialize(4, 3500.0, 5);
  32.    cout << "The sedan carries " << sedan.passengers() << 
  33.                                                     " passengers.\n";
  34.    cout << "The sedan weighs " << sedan.get_weight() << " pounds.\n";
  35.    cout << "The sedan's wheel loading is " << 
  36.                     sedan.wheel_loading() << " pounds per tire.\n\n";
  37.  
  38. truck semi;
  39.  
  40.    semi.initialize(18, 12500.0);
  41.    semi.init_truck(1, 33675.0);
  42.    cout << "The semi weighs " << semi.get_weight() << " pounds.\n";
  43.    cout << "The semi's efficiency is " << 
  44.                           100.0 * semi.efficiency() << " percent.\n";
  45. }
  46.  
  47.  
  48.  
  49.  
  50. // Result of execution
  51. //
  52. // The unicycle has 1 wheel.
  53. // The unicycle's wheel loading is 12.5 pounds on the single tire.
  54. // The unicycle weighs 12.5 pounds.
  55. //
  56. // The bicycle has 2 wheels.
  57. // The bicycle's wheel loading is 19 pounds per tire.
  58. // The bicycle weighs 38 pounds.
  59. //
  60. // The sedan carries 5 passengers.
  61. // The sedan weighs 3500 pounds.
  62. // The sedan's wheel loading is 875 pounds per tire.
  63. //
  64. // The semi weighs 12500 pounds.
  65. // The semi's efficiency is 72.929072 percent.
  66.