《C++实验报告定义一个汽车类Vehicle》由会员分享,可在线阅读,更多相关《C++实验报告定义一个汽车类Vehicle(2页珍藏版)》请在金锄头文库上搜索。
1、编辑一个 C+ 设计一个程序,定义一个汽车类 Vehicle,它具有一个需要传递参数的构造函数,类中的数据包括:车轮个数 wheel 和车重 weight,两者作为保护成员;小车类 Car 是它的私有派生类,其中包括承载人数 passengers;卡车类 Truck 是 Vehicle 的私有派生类,其中包括承载人数 passengers 和载重量 payload。每个类都有相关数据的输出方法。class Vehicleprotected:int wheels;float weight;public:Vehicle(int wh, float we): wheels(wh), weight(w
2、e) void display();int getWheels();float getWeight();class Car: private Vehicleprivate: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 Vehicleprivate: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();