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;
}
相关推荐
AAD555888992 天前
基于YOLO13-C3k2-IDWC的汽车损伤检测技术研究_1
汽车
雨大王5122 天前
怎么打造一个能自我进化的制造数字基座?
人工智能·汽车·制造
JicasdC123asd2 天前
使用Faster R-CNN模型训练汽车品牌与型号检测数据集 改进C4结构 优化汽车识别系统 多类别检测 VOC格式
r语言·cnn·汽车
Godspeed Zhao2 天前
现代智能汽车中的无线技术11.1——蜂窝移动通信技术(11)
汽车·信息与通信
雨大王5123 天前
如何选择适合自己企业的工业智能体解决方案?
人工智能·汽车·制造
河北北重机械9663 天前
发动机试验台底座:汽车研发的关键支撑
汽车·试验台铁地板·试验铁底座铸造·铸铁试验平台加工
爱思考的发菜_汽车网络信息安全3 天前
汽车网络安全:RSA算法详细解析
安全·web安全·汽车
NewCarRen3 天前
硬件在环HIL(七):发电机的被控对象模型
汽车
chipsense4 天前
集成三相霍尔电流传感器在新能源汽车中的应用探讨
汽车·霍尔电流传感器
雨大王5124 天前
汽车制造如何实现全链路智能化转型?
汽车·制造