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;
}
相关推荐
安当加密5 天前
智能网联汽车如何守住“信任根”? CAS 构建汽车行业专用密钥管理体系
汽车
LVXIANGAN5 天前
汽车智能座舱中LVDS、CAN、以太网、RTP的区别
自动驾驶·汽车
LONGZETECH5 天前
技术解析|比亚迪秦 PLUS EV 故障诊断仿真软件,院校实训落地最优解
汽车·汽车仿真教学软件·汽车教学软件
雨大王5125 天前
整车制造计划排程排产系统的创新与实践
人工智能·汽车·制造
RunsenLIu5 天前
基于 Spring Boot 3 与 Vue 3 的汽车租赁系统
vue.js·spring boot·汽车
ws2019075 天前
聚焦测试测量新机遇,AUTO TECH China 2026广州汽车技术展锚定行业未来
人工智能·科技·汽车
汽车仪器仪表相关领域6 天前
动态诊断充电中枢:DCA-8000型动态诊断充电系统 4S店/维修连锁/新能源服务站/车队维保全场景实战全解
人工智能·车载系统·汽车·负载均衡·压力测试·可用性测试
lfPCB6 天前
汽车电子的“热管理师”:铝基板在新能源汽车中的应用
汽车
天天爱吃肉82186 天前
【功率分析仪在新能源汽车研发测试中的核心应用与工程师能力进阶(实战版)】
人工智能·嵌入式硬件·机器学习·汽车
Godspeed Zhao8 天前
现代智能汽车中的无线技术108——ETC(2)
汽车