Programming Problem, November 18th, 1998
Building a car for a class
Suppose that you were to build a class for a company that rents
cars... (ok, this is a silly example). You want to keep track of
certain information regarding each car that is owned by the company,
and you want to provide functions that will enable them to
store/retrieve information regarding those cars.
Data to keep track of:
- Brand
- Year
- Mileage
- Capacity
- Color
- Availability (remember, it is for a company that rents car, so
you want to know if the car is rented or not)
Functions to build:
- Initialize: this function lets you create a new car. You can
either use the basic initialize function (i.e. with no parameters) to
built a default car, or you can build a custom one, by passing
parameters.
- Print info: this function displays all the information about a
given car
- updatemileage: when someone returns a car, you want to update the
mileage of the car.
- "age": you pass the present year to the age function, and it will
return how old the car is.
- getcapacity: this function should return the capacity of the car
- isavailable: returns true if the car is available, o/w returns
false
- changecolor: well, someone just had a bad accident with the car,
and you decide to repaint it with a different color... you need to
update the info!
Of course, there are many many many other things you could do... Feel
free to add them!
The following files contain the code:
car.h : contains the class
car.cc : contains the definitions for the public member
functions of the class
carmain.cc : a sample main
To compile this program, just type:
g++ car.cc carmain.cc -o car