Source of car.hpp


  1: /** @file car.hpp

  2: Based on an example from N. Josuttis, Object-Oriented Programming in C++.

  3: */
  4: 
  5: #include <iostream>

  6: using namespace std;
  7: 
  8: namespace Josuttis
  9: {
 10:     class Car
 11:     {
 12:     public:
 13:         Car
 14:         (
 15:             int distance = 0 //in

 16:         )
 17:         : km(distance)
 18:         {
 19:             cout << "\nCar constructor called.";
 20:             cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
 21:         }
 22: 
 23:         virtual ~Car()
 24:         {
 25:             cout << "\nCar destructor called.";
 26:             cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
 27:         }
 28: 
 29:         virtual void travel
 30:         (
 31:             int distanceTraveled //in

 32:         )
 33:         {
 34:             km += distanceTraveled;
 35:         }
 36: 
 37:         virtual void display()
 38:         {
 39:             cout << "\nThe car has traveled " << km
 40:                 << " kilometers on land.";
 41:             cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
 42:         }
 43: 
 44:     protected:
 45:         int km; //Land distance traveled

 46:     };
 47: }