当前位置: 首页 > news >正文

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。每个类都有相关数据的输出方法。

代码实现:

#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;
}

相关文章:

  • Python-字典详解
  • 阿里云租赁费用_阿里云服务器多配置报价表
  • C语言实现植物大战僵尸(完整版)
  • 基于JavaScript的jimp库处理图片,添加绘制点
  • 阿里云新版公共实例从注册账号到创建设备生成参数教程
  • 【微信小程序】上传头像 微信小程序内接小程序客服
  • Apache Doris 详细教程(三)
  • 外包干了3个月,技术倒退2年。。。
  • 【EasyExcel实践】万能导出,一个接口导出多张表以及任意字段(可指定字段顺序)
  • TimeGPT:时间序列预测模型实例
  • 【系统运维】Centos部署Haproxy+Keepalived+RabbitMQ高可用集群
  • Vue3自定义Hooks定义
  • 2023年十大网络安全上市公司观察
  • 15:00面试,15:06就出来了,问的问题有点变态。。。
  • http和https的区别有哪些
  • 利用 Python进行数据分析实验(一)
  • 网络中常说的QOS是什么,又有什么作用
  • 用python写一个简单的爬虫
  • IDC MarketScape2023年分布式数据库报告:OceanBase位列“领导者”类别,产品能力突出
  • Apache Flink(七):Apache Flink快速入门 - DataStream BATCH模式
  • 中国社科院:网文市场超430亿元,作者破3000万人
  • 当创业热土遇上年轻气息,上海南汇新城发展如何再发力?
  • 河北邯郸一酒店婚宴发生火灾:众人惊险逃生,酒店未买保险
  • 价格周报|供需回归僵局,本周生猪均价与上周基本持平
  • 印巴战火LIVE丨“快速接近战争状态”?印度袭击巴军事基地,巴启动反制军事行动
  • 三大猪企4月生猪销量同比均增长,销售均价同比小幅下降