zoukankan      html  css  js  c++  java
  • 自考新教材-p243_5_(1)

    源程序:

    #include <iostream>
    using namespace std;

    class vehicle
    {
    public:
    int wheels;
    float weight;
    public:
    vehicle(int wheels1, float weight1)
    {
    wheels = wheels1;
    weight = weight1;
    }
    int get_wheels()
    {
    return wheels;
    }
    float get_weight()
    {
    return weight;
    }
    void show()
    {
    cout << "轮胎数:"<<wheels << "," << "车重:"<<weight << endl;
    }
    ~vehicle()
    {}
    };

    class car :public vehicle
    {
    protected:
    int speed_max;
    car(int wheels2, float weight2, int speedmax) :vehicle(wheels2, weight2)
    {
    speed_max = speedmax;
    cout << "最大速度:"<<speed_max << endl;
    }

    ~car()
    {}
    };
    class toyota_car :public car
    {
    private:
    double length, width, height;
    public:
    toyota_car(int wheels3, float weight3, int speedmax3, double length3, double width3, double height3) :car(wheels3, weight3, speedmax3)
    {
    length = length3;
    width = width3;
    height = height3;
    }
    void show3()
    {
    cout << "车长:"<<length << "," << "车宽:" << width << "," << "车高:" << height << endl;
    }
    ~toyota_car()
    {}
    };

    int main()
    {
    vehicle ve(4,2.4);
    ve.show();
    toyota_car tcar(4,2.4,240,4.8,1.85,1.65);

    tcar.show3();
    system("pause");
    return 1;
    }

    运行结果:

  • 相关阅读:
    交换相邻字符(CharBuffer)
    ANSI和UNICODE
    关键路径
    拓扑排序 java
    MySql 中group by使用
    面试题2
    面试题
    K8S如何限制资源使用
    Kubernetes中配置Pod的liveness和readiness探针
    sed入门详解教程
  • 原文地址:https://www.cnblogs.com/duanqibo/p/12260744.html
Copyright © 2011-2022 走看看