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;
}
相关推荐
明志数科14 小时前
产线回流数据的工程价值、三类边界与多源数据配比:机器人进厂常态化下的数据供给分析
机器人·汽车·媒体
工业涂料百问17 小时前
汽车内外饰涂层为什么要过 IATF 16949:体系要求与涂装工艺的对应关系
汽车
TOSUN同星2 天前
TSMaster 9月功能亮点:旋钮控件、三大模块、报文过滤、SOMEIP静态注册全升级
汽车·软件工程
汽车人——Yin3 天前
CANOE实战——诊断测试
汽车·canoe·uds诊断
树欲静而风不止863 天前
APQP 五大阶段拆解与阶段关口(Gate)管控实践
汽车
丹尼克尔自动化科技有限公司5 天前
丹尼克尔无线拧紧枪 如何破解汽车总装内饰装配痛点?
汽车·汽车装配·无线拧紧枪·无线拧紧工具·智能拧紧工具
MIXrer5 天前
场馆引入沙盘赛车,为什么能成为第二消费场景?
汽车·旅游·娱乐
沐欣工作室_lvyiyi6 天前
基于单片机的汽车智能座舱控制系统的设计与实现(论文+源码)
单片机·嵌入式硬件·汽车·智能座舱
YH行业报告分析6 天前
2026锌铝片涂层市场:无铬化转型与薄涂层耐蚀技术如何重构汽车紧固件防腐标准?
重构·汽车
2601_967287576 天前
变速箱油瓶身上的认证代号,怎么对到自己的车上
汽车