class Vehicle
{
protected:
int wheels;
float weight;
public:
Vehicle(int wh, float we): wheels(wh), weight(we) {}
void display();
int getWheels();
float getWeight();
};
class Car: private Vehicle
{
private:
int passengers;
public:
Car(int wh, float we, int pa): Vehicle(wh, we), passengers(pa) {}
int getPassengers();
void display();
};
void Car::display()
{
cout << "wheels: " << wheels << endl;
cout << "weight: " << weight << endl;
cout << "passengers: " << passengers << endl;
}
class Trunk: private Vehicle
{
private:
float payload;
int passengers;
public:
Trunk(int wh, float we, int pay, int pas): Vehicle(wh, we), payload(pay), passengers(pas) {}
float getPayload();
int getPassengers();
void display();
};
温馨提示:内容为网友见解,仅供参考