10-B. 交通工具(多重继承)

10-多继承
题目描述
1、建立如下的类继承结构:

1)一个车类CVehicle作为基类,具有max_speed、speed、weight等数据成员,display()等成员函数

2)从CVehicle类派生出自行车类CBicycle,添加属性:高度height

3)从CVehicle类派生出汽车类CMotocar,添加属性:座位数seat_num

4)从CBicycle和CMotocar派生出摩托车类CMotocycle

2、分别定义以上类的构造函数、输出函数display及其他函数(如需要)。

3、在主函数中定义各种类的对象,并测试之,通过对象调用display函数产生输出。

输入
第一行:最高速度 速度 重量 第二行:高度 第三行:座位数

输出
第一行:Vehicle: 第二行及以后各行:格式见Sample

100 60 20
28
2

Vehicle:
max_speed:100
speed:60
weight:20

Bicycle:
max_speed:100
speed:60
weight:20
height:28

Motocar:
max_speed:100
speed:60
weight:20
seat_num:2

Motocycle:
max_speed:100
speed:60
weight:20
height:28
seat_num:2

#include<iostream>
using namespace std;

class vehicle
{
   
   
protected:
    int max,speed,weight;
public:
    vehicle(int m,int s,int w):max(m),speed(s),weight(w){
   
   }
    void display()
    {
   
   
        cout<<"Vehicle:"<<endl;
        cout<<"max_speed:"<<max<<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值