求教一个C++题目,大神来帮忙~~~~!!!!

来源:百度知道 编辑:UC知道 时间:2024/07/02 22:49:35
有一个汽车类vehicle,它具有一个需传递参数的构造函数,类中数据成员:车轮个数wheels和车重weight放在保护段中;小车类car是它的私有派生类,其中包含载人数 passenger_load;卡车类truck是vehicle的私有派生类,其中包含载人数passenger_load和载重量payload。每个类都有相关数据的输出方法。
大神帮忙哇~~~

#include<iostream>
using namespace std;
class vehicle // 定义汽车类
{
public:
vehicle(int wheels,float weight);
int get_wheels();
float get_weight();
float wheel_load();
void show();
protected:
int wheels; // 车轮数
float weight; // 重量
};
class car:public vehicle // 定义小车类
{
public:
car(int wheels,float weight,int passengers=4);
int get_passengers();
void show();
private:
int passenger_load; // 载人数
};
class truck:public vehicle // 定义卡车类
{
public:
truck(int wheels,float weight,int passengers=2,float max_load=24000.00);
int get_passengers();
float efficiency();
void show();
private:
int passenger_load; // 载人数
float payload; // 载重量
};
vehicle::vehicle(int wheels,float weight)
{
vehicle::wheels=wheels;
vehicle::weight=weight;
}
int vehicle::ge