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;
}
相关推荐
network_tester14 小时前
TSN网络流量及协议测试:为确定性网络护航的关键技术
网络·网络协议·车载系统·汽车·信息与通信·信号处理
杉岩数据19 小时前
杉岩数据携IDM亮相苏州汽车产业链创新论坛,展示检测数据管理方案实践
人工智能·汽车·视觉检测·质量管理·质量追溯·质量数据
金智维科技官方19 小时前
金智维×吉利汽车车机智能体,入选36氪2026 AI最佳场景渗透案例
人工智能·ai·自动化·汽车·智能体
wechat_Neal1 天前
座舱域控-架构基础1.1
人工智能·汽车
2zcode2 天前
基于Multisim的汽车尾灯顺序控制电路模块化设计与仿真
汽车
ws2019072 天前
2026广州汽车电子与软件展:软件定义汽车时代的核心驱动力与产业新坐标
科技·汽车
谁似人间西林客2 天前
汽车智能制造如何解决混线生产与质量追溯难题?
大数据·汽车·制造
盟接之桥2 天前
制造业电子数据交换(EDI)应用 | 汽车零配件方案
网络·安全·低代码·汽车·制造
wechat_Neal2 天前
座舱域控-架构基础1
汽车
Bode_20023 天前
汽车零部件智能工厂物流设计框架
人工智能·汽车·制造·物流