c++.高手进

来源:百度知道 编辑:UC知道 时间:2024/07/04 23:51:11
定义一个车辆(vehicle)基类,具有MaxSpeed等成员变量,Run和Stop等成员函数,由此派生出自行车(bicycle)类、汽车(motorcar)类。自行车类有高度(height)等属性,汽车类有座位数(Seat)等属性。从bicycle和motorcar派生出摩托车(motorcycle)类。在main中使用这三个类,注意使用虚基类。
希望写得完整,比较好点,谢谢了,答完一定给分

class vehicle
{
public:
virtual Run() = 0; //定义2个纯虚函数
virtual Stop() = 0;
private:
int MaxSpeed;
};

class bicycle : public vehicle
{
public:
Run()
{
cout << "bicycle is running" << endl;
}

Stop()
{
cout << "bicycle has been stoped" << endl;
}

};

class motorcar : public vehicle
{
public:
Run()
{
cout << "motorcar is running" << endl;
}

Stop()
{
cout << "motorcar has been stoped" << endl;
}

};

class motorcycle : public bicycle, motorcar
{
public:
Run()
{
cout << "motorcycle is running" << endl;
}

Stop()
{
cout << "motorcycle has been stoped" << endl;
} <