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;
}
相关推荐
小昭dedug12 小时前
汽车为什么需要以太网?带宽?实时?
汽车
TsingtaoAI21 小时前
企业内训|智能调控系统算法与优化——某汽车厂商
算法·汽车·ai企业内训·自动驾驶企业内训·智驾企业培训
一点.点1 天前
《智能网联汽车 自动驾驶功能道路试验方法及要求》 GB/T 44719-2024——解读
自动驾驶·汽车
高工智能汽车1 天前
AI汽车时代的全面赋能者:德赛西威全栈能力再升级
人工智能·microsoft·汽车
天天爱吃肉82181 天前
比亚迪全栈自研生态的底层逻辑
汽车
UI设计兰亭妙微2 天前
UI设计公司兰亭妙微分享:汽车 MHI 设计的界面布局创新法则
汽车
studyer_domi2 天前
Matlab 车辆四自由度垂向模型平稳性
开发语言·matlab·汽车
九河云2 天前
汽车制造行业的数字化转型
大数据·科技·重构·汽车·制造
天天爱吃肉82182 天前
基于NI-PXI的HIL系统开发
汽车·智能硬件
十六宿舍2 天前
【MCAL】TC397+EB-tresos之I2c配置实战(同步、异步)
单片机·汽车·autosar·嵌入式开发·mcal·基础软件