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;
}
相关推荐
Luminbox紫创测控2 小时前
一文了解太阳光模拟器的汽车材料老化测试及标准解析
汽车
毕设源码-郭学长13 小时前
【开题答辩全过程】以 汽车知名品牌信息管理系统为例,包含答辩的问题和答案
汽车
天理智能科技14 小时前
PlantSimulation 在汽车总装车间配送物流仿真中的应用
汽车
华普微HOPERF14 小时前
数字隔离器,新能源汽车PTC中的“电气安全卫士”
科技·物联网·汽车
CHOTEST中图仪器14 小时前
三坐标测量机在汽车制造行业中的应用
汽车·制造·三坐标测量机
财经三剑客14 小时前
深蓝汽车人事调整:邓承浩升任董事长,姜海荣出任首席执行官
汽车
城南皮卡丘1 天前
基于YOLO8的汽车碰撞事故检测系统【数据集+源码+文章】
汽车
地平线开发者2 天前
理想汽车智驾方案介绍 4 World model + 强化学习重建自动驾驶交互环境
人工智能·自动驾驶·汽车
智者知已应修善业2 天前
【multisim汽车尾灯设计】2022-12-1
驱动开发·经验分享·笔记·汽车·硬件架构·硬件工程
恒州博智QYResearch咨询2 天前
全球汽车氮化镓技术市场规模将于2031年增长至180.5亿美元,2025-2031年复合增长率达94.3%,由Infineon和Navitas驱动
大数据·汽车