Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement