6-55.汽车类的继承

根据给定的汽车类vehicle(包含的数据成员有车轮个数wheels和车重weight)声明,完成其中成员函数的定义,之后再定义其派生类并完成测试。

小车类car是它的派生类,其中包含载人数passenger_load。每个类都有相关数据的输出方法。

输出样例:

在这里给出相应的输出。例如:

Type:Vehicle

Wheel:4

Weight:1000kg

Type:Car

Type:Vehicle

Wheel:4

Weight:2000kg

Load:5 persons

它的派生类,其中包含载人数passenger_load。每个类都有相关数据的输出方法。

代码实现:

cpp 复制代码
#include<iostream>
using  namespace  std;  
class  Vehicle  
{  
        protected:  
                int  wheels;  
                float  weight;  
        public:  
                Vehicle(int  wheels,float  weight);  
                int  get_wheels();  
                float  get_weight();  
                float  wheel_load();  
                void  show();  
};  

/*  请在这里填写答案  */
class Car : public Vehicle{
	private:
		int passenger_load;
	public:
		Car(int a,float b,int c):Vehicle(a,b){
			passenger_load=c;
		}
		void show(){
			cout<<"Type:Car"<<endl;
			Vehicle::show();
			cout<<"Load:"<<passenger_load<<" persons"<<endl;
		}
		
};

Vehicle::Vehicle(int wheels,float weight):wheels(wheels),weight(weight){
}
void Vehicle::show(){
	cout<<"Type:Vehicle"<<endl;
	cout<<"Wheel:"<<wheels<<endl;
	cout<<"Weight:"<<weight<<"kg"<<endl;
}

int  main  ()  
{  
        Vehicle  v(4,1000);
        v.show();  
        Car  car1(4,2000,5);    
        car1.show  ();  
        return  0;
}
相关推荐
天天爱吃肉82189 小时前
新能源汽车热管理核心技术解析:冬季续航提升40%的行业方案
android·python·嵌入式硬件·汽车
小疆智控21 小时前
Modbus转Ethernet IP赋能挤出吹塑机智能监控
汽车·制造
虹科Pico汽车示波器1 天前
汽车免拆诊断案例 | 2010款捷豹XFL车制动警告灯、DSC警告灯异常点亮
汽车·汽车示波器·can总线·汽修案例·总线故障·捷豹xfl·动态稳定控制系统故障
vicorv251 天前
霍尔效应传感器的革新突破:铟化铟晶体与结构演进驱动汽车点火系统升级
汽车
CHENKONG_CK1 天前
RFID推动新能源汽车零部件生产系统管理应用案例
汽车
赛卡2 天前
汽车安全:功能安全FuSa、预期功能安全SOTIF与网络安全Cybersecurity 解析
人工智能·安全·网络安全·车载系统·自动驾驶·汽车
ACQTEC研索仪器2 天前
案例分享--汽车制动卡钳DIC测量
图像处理·汽车·dic·数字图像相关·vic-3d非接触全场应变测量
猎板PCB 邹亮2 天前
猎板硬金镀层厚度:新能源汽车高压系统的可靠性基石
汽车·pcb工艺
weixin_460186132 天前
基于51单片机的汽车雨刮器模拟proteus仿真
汽车·51单片机·proteus
MYH5162 天前
汽车停车匹配充电桩随机森林
python·随机森林·汽车