SHARE
TWEET

Untitled

a guest Aug 14th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef CAR_H
  2. #define CAR_H
  3.  
  4. #include <string>
  5. using std::string;
  6. using std::cout;
  7.  
  8. class Car {
  9.   public:
  10.     void PrintCarData();
  11.     void IncrementDistance();
  12.    
  13.     // Using a constructor list in the constructor:
  14.     Car(string c, int n) : color(c), number(n) {}
  15.  
  16.   // The variables do not need to be accessed outside of
  17.   // functions from this class, so we can set them to private.
  18.   private:
  19.     string color;
  20.     int distance = 0;
  21.     int number;
  22. };
  23.  
  24. #endif
  25. ------------------------------------------------------------------------------------------
  26. #include <iostream>
  27. #include "car.h"
  28.  
  29. // Method definitions for the Car class.
  30. void Car::PrintCarData()
  31. {
  32.     cout << "The distance that the " << color << " car " << number << " has traveled is: " << distance << "\n";
  33. }
  34.  
  35. void Car::IncrementDistance()
  36. {
  37.     distance++;
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top