My professor gave us a set of class specifications for three classes. Vehicle, Car, and Truck. My vehicle class works fine, and utilizing it in the other classes is fine as well but I'm having trouble implementing the individual class specifications in the other two. Really the only thing I have to do is somehow say whether or not the car is a race car. I've never worked with boolean functions (just never had to so far) so another problem is that I'm not sure about how to write the driver in main either. Any help would be appreciated.
Code posted below. I'm going one class at a time so the truck class is empty but I'll fill that in once Car is taken care of. Any input anywhere though would be very helpful. Thanks in advance.
[LIST=1]
[*]#include<iostream>
[*]using namespace std;
[*]class Vehicle
[*]{
[*]public:
[*]
[*]
[*] Vehicle();
[*] ~Vehicle();
[*] void setAge(int i){Age = i;};
[*] void setPrice(float i) {Price = i;};
[*] int getAge()const;
[*] float getPrice()const;
[*]
[*]private:
[*] int Age;
[*]protected:
[*] float Price;
[*]};
[*]Vehicle::Vehicle()
[*]{
[*] Age = 0;
[*] Price = 0;
[*]}
[*]Vehicle::~Vehicle()
[*]{
[*] Age = 0;
[*] Price = 0;
[*]}
[*]int Vehicle::getAge() const
[*]{
[*] return Age;
[*]}
[*]float Vehicle::getPrice() const
[*]{
[*] return Price;
[*]}
[*]class Car : public Vehicle
[*]{
[*]public:
bool RaceCarStatus()const; //boolean, yes or no
[*] Car(); //default constructor, sets RaceCarStatus=false
[*] //need copy constructor, takes one parameter of class car
[*] ~Car(); //destructor
[*] void setRaceCarStatus(int i);//takes boolean parameter, returns nothing
[*] bool getRaceCarStatus()const;//no parameters, returns status
[*]};
[*]Car::Car()
[*]{
[*] int i;
[*] i = 0;
[*]}
[*]Car::~Car()
[*]{
[*] int i;
[*] i = 0;
[*]}
[*]void Car::setRaceCarStatus(int i)
[*]{
[*] RaceCarStatus = i;
[*]}
[*]bool Car::RaceCarStatus()
[*]{
[*] int i;
[*] if (i = 1)
[*] return true;
[*] else return false;
[*]
[*]}
[*]bool Car::getRaceCarStatus() const
[*]{
[*] return RaceCarStatus;
[*]}
[*]class Truck : public Vehicle
[*]{
[*] //DieselTypeStatus, boolean, private, yes or no
[*] //default constructor, set DieselTypeStatus=false
[*] //parametric constructor, takes boolean,sets DieselTypeStatus=boolean
[*] //destructor, DieselTypeStatus=false
[*] //setDieselTypeStatus() takes boolean parameter, return nothing
[*] //getDieselTypeStatus() no parameters, return DieselTypeStatus
[*]};
[*]int main()
[*]{
[*]Vehicle x;
[*]cout << "Initial value for x: " << endl;
[*]cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << endl;
[*]x.setAge(40);
[*]x.setPrice(20000);
[*]cout << "Modified value for x: " << endl;
[*]cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << endl;
[*]cout << endl;
[*]Car y;
[*]cout << "Initial value for y: " << endl;
[*]cout << "Age = " << y.getAge() << " Price= " << y.getPrice() << endl;
[*]y.setAge(70);
[*]y.setPrice(130);
[*]cout << "Modified value for y: " << endl;
[*]cout << "Age = " << y.getAge() << " Price= " << y.getPrice() << endl;
[*]cout << "Initial race car status for y: " << y.getRaceCarStatus()<< endl;
[*]//y.setRaceCarStatus(1);
[*]//cout << "Modified race car status for y " << y.getRaceCarStatus() << endl;
[*]cout << endl;
[*]Truck z;
[*]cout << "Initial value for z: " << endl;
[*]cout << "Age = " << z.getAge() << " Price= " << z.getPrice() << endl;
[*]z.setAge(10);
[*]z.setPrice(10000);
[*]cout << "Modified value for z: " << endl;
[*]cout << "Age = " << z.getAge() << " Price= " << z.getPrice() << endl;
[*]return 0;
[*]}
[/LIST]