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;
}
相关推荐
稳联技术13 小时前
汽车焊机数据通信:Profinet转Canopen网关的神奇连接
服务器·网络·汽车
毕设木哥15 小时前
计算机专业毕业设计推荐-基于python的汽车汽修保养服务平台
大数据·python·计算机·django·汽车·毕业设计·课程设计
achirandliu15 小时前
汽车电子电气架构从12V提升至48V,带来那些好处? 包括那些改变?
架构·汽车·汽车电子电气架构·从12v升到48v
lupai16 小时前
盘点实用的几款汽车类接口?
大数据·人工智能·汽车
achirandliu16 小时前
汽车英文单词缩写汇总
汽车·汽车英文单词
Java追光着16 小时前
扣子智能体实战-汽车客服对话机器人(核心知识:知识库和卡片)
人工智能·机器人·汽车·智能体
车载诊断技术18 小时前
电子电气架构——中央计算的软件定义汽车架构
网络·架构·汽车·soa·电子电器架构
上海知从科技18 小时前
喜报 | 知从科技荣获 “AutoSec 安全之星 - 优秀汽车软件供应链安全方案奖”
科技·安全·汽车
亚远景aspice18 小时前
ISO 26262功能安全标准与汽车软件代码质量的关系探讨
安全·汽车
稳联技术18 小时前
Canopen-pn有线通信标准在汽车制造中至关重要
汽车·制造