class CAR{ protected: int speed; public: CAR(int s){ speed = s; } ~CAR(){ } void Show(){ cout<<"Speed: "<<speed<<endl; } };

class BUS:public CAR{ protected: int seat; public: BUS(int s, int t):CAR(s){ seat = t; } ~BUS(){ } void Show(){ cout<<"Speed: "<<speed<<endl; cout<<"Seat: "<<seat<<endl; } };

class TRUCK:public CAR{ protected: int load; public: TRUCK(int s, int t):CAR(s){ load = t; } ~TRUCK(){ } void Show(){ cout<<"Speed: "<<speed<<endl; cout<<"Load: "<<load<<endl; } };

class VAN:public BUS, public TRUCK{ public: VAN(int s, int t, int u):BUS(s,t),TRUCK(s,u),CAR(s){ } ~VAN(){ } void Show(){ cout<<"Speed: "<<speed<<endl; cout<<"Seat: "<<seat<<endl; cout<<"Load: "<<load<<endl; } }

请设计以下汽车、客车、货车、客货两用车等4个类。CAR 为汽车类是公共基类提供汽车的基本功能。包括:一个保护数据成员:speed速度。三个公有成员函数:构造函数初始化速度、析构函数和 Show 函数显示速度。BUS 为客车类以公有方式继承 CAR 类在汽车类的基础上增加客运功能。包括:一个保护数据成员:seat载客量。三个公有成员函数:构造函数初始化速度和载客量、析构函数和 Show 函数显示速度

原文地址: https://www.cveoy.top/t/topic/ecUm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录