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;
}
相关推荐
亚远景aspice34 分钟前
亚远景-ISO/PAS 8800在软件定义汽车(SDV)时代的AI安全治理角色
安全·汽车
dj0321127 小时前
咸阳机场停车省钱攻略
汽车
Shadow_learnup8 小时前
英飞凌 LITIX™ Interior:汽车内饰氛围灯解决方案
汽车
万俟淋曦11 小时前
NVIDIA DriveOS 推动新一代智能汽车实现突破
人工智能·ai·汽车·nvidia·智能汽车·driveos·driveworks
财经三剑客1 天前
深蓝汽车10月全球销量36792辆 S05销量突破2万辆
汽车
NewCarRen1 天前
自动驾驶汽车与利益相关者互动的功能安全与网络安全分析方法
安全·网络安全·自动驾驶·汽车
武子康2 天前
AI研究-116 特斯拉 HW3.0 与 HW4.0 区别详解:摄像头分辨率、FSD算力、雷达与Vision泊车
人工智能·深度学习·计算机视觉·ai·自动驾驶·汽车·视觉检测
乐吾乐科技2 天前
乐吾乐3D可视化案例【智慧汽车三维可视化】
3d·汽车
深圳南柯电子4 天前
纯电汽车EMC整改:预防性设计节省47%预算|深圳南柯电子
网络·人工智能·汽车·互联网·实验室·emc
SelectDB技术团队4 天前
货拉拉用户画像基于 Apache Doris 的数据模型设计与实践
数据分析·汽车·apache·用户画像·货拉拉