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;
}
相关推荐
向上的车轮11 分钟前
飞桨PaddlePaddle:在汽车零部件制造中的工业自动化应用详解
汽车·制造·paddlepaddle
狮驼岭的小钻风13 分钟前
汽车V模型开发流程、ASPICE、汽车功能安全的基石是国际标准 ISO 26262
网络·安全·汽车
毕设源码-郭学长19 小时前
【开题答辩全过程】以 个性化汽车推荐系统为例,包含答辩的问题和答案
汽车
Godspeed Zhao20 小时前
现代智能汽车中的无线技术72——SatCom(0)
汽车
天天爱吃肉82181 天前
【跨界封神|周杰伦×王传福(陶晶莹主持):音乐创作与新能源NVH测试,底层逻辑竟完全同源!(新人必看入行指南)】
python·嵌入式硬件·算法·汽车
AAD555888992 天前
基于YOLO13-C3k2-IDWC的汽车损伤检测技术研究_1
汽车
雨大王5123 天前
怎么打造一个能自我进化的制造数字基座?
人工智能·汽车·制造
JicasdC123asd3 天前
使用Faster R-CNN模型训练汽车品牌与型号检测数据集 改进C4结构 优化汽车识别系统 多类别检测 VOC格式
r语言·cnn·汽车
Godspeed Zhao3 天前
现代智能汽车中的无线技术11.1——蜂窝移动通信技术(11)
汽车·信息与通信
雨大王5123 天前
如何选择适合自己企业的工业智能体解决方案?
人工智能·汽车·制造