Lab 2 -- Classes and Objects
Write a class named Car that has (at least) the following member variables:
- year. An int that holds the car's model year.
- make. A string that holds the make of the car.
- speed. An int that holds the car's current speed.
- odometer. An int that holds the total number of miles the car has traveled.
In addition, the class should have the following member functions:
- Constructor. The constructor should accept the car's make and year as arguments and assign these values to the object's year and make member variables. The constructor should initialize the speed member variable to 0 and the odometer member variable to 0.
- Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's year, make, speed, and distance member variables.
- accelerate. This function should add 5 to the speed member variable each time it is called.
- brake. This function should subtract 5 from the speed member variable each time it is called.
- takeTrip. This function should accept a number of miles that the car is traveling and modify the odometer member variable to reflect the distance being traveled.
Demonstrate the class in a program that creates a Car object, asks the user how fast to go, and calls the accelerate function that many times.
Then, display the speed of your Car object (by calling the accessor function).
Finally, call the brake function twice, and display the speed again.
Feel free to experiment and add other functionality as you deem appropriate!