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;
}
相关推荐
Godspeed Zhao3 小时前
现代智能汽车系统——智驾SoC之框架版图
人工智能·机器学习·自动驾驶·汽车·soc
Sinowintop6 小时前
在全球化扩展的同时,OFTP2持续筑牢网络安全防线
汽车·edi·供应链·汽车行业·国产edi·oftp·odette
曾响铃7 小时前
透过加特兰感知与通信双芯策略,再看法规下汽车智能化周期的确定性红利
汽车
探物 AI8 小时前
【3D·感知】从PointNet到PointPillars:如何让自动驾驶汽车“实时“看见3D世界?
3d·自动驾驶·汽车
DeepCeLa9 小时前
氧化铈:汽车三元催化器里的“氧管理大师”
汽车·稀土·稀土科技
盟接之桥9 小时前
电子数据交换(EDI)|制造业汽车零配件场景方案
大数据·网络·人工智能·安全·低代码·汽车·制造
Godspeed Zhao9 小时前
Level 4自动驾驶系统设计4——功能与场景4
人工智能·自动驾驶·汽车
YunQuality1 天前
云质QMS:汽车零部件行业质量管理数字化解决方案
汽车·软件需求·工业软件
shushangyun_1 天前
汽车服务行业B2B平台+AI解决方案哪家专业:2026年最新测评
java·运维·网络·数据库·人工智能·汽车
天天爱吃肉82181 天前
豆包 vs DeepSeek API 对比分析报告
android·java·大数据·开发语言·功能测试·嵌入式硬件·汽车