Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef CAR_H
- #define CAR_H
- #include <string>
- using std::string;
- using std::cout;
- class Car {
- public:
- void PrintCarData();
- void IncrementDistance();
- // Using a constructor list in the constructor:
- Car(string c, int n) : color(c), number(n) {}
- // The variables do not need to be accessed outside of
- // functions from this class, so we can set them to private.
- private:
- string color;
- int distance = 0;
- int number;
- };
- #endif
- ------------------------------------------------------------------------------------------
- #include <iostream>
- #include "car.h"
- // Method definitions for the Car class.
- void Car::PrintCarData()
- {
- cout << "The distance that the " << color << " car " << number << " has traveled is: " << distance << "\n";
- }
- void Car::IncrementDistance()
- {
- distance++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement