c++的编程题基础好的高手帮帮忙!

2、 定义一个车(vehicle)基类,具有MaxSpeed、Weight等成员变量,Run、Stop等成员函数,由此公有派生出自行车(bicycle)类、汽车(motorcar)类。自行车(bicycle)类有高度(height)等属性,汽车(motorcar)类有座位数(SeatNum)等属性。从bicycle和motorcar公有派生出摩托车(motorcycle)类,把vehicle设置为虚基类
include <iostream.h>
class vehicle
{
private:
int maxspeed;
int weight;
public:
void run(){cout<<"maxspeed"<<endl;}
void stop(){cout<<"weight"<<endl;}
};
class biycle:virtual public vehicle
{
private:
int height;
public:
void yy(){cout<<"height"<<run()<<stop()<<endl;}
};
class motorcar:virtual public vehicle
{
private:
int seatsum;
public:
void yy1(){cout<<"seatsum"<<run()<<stop()<<endl;}
};

class motorcycle:public biycle,public motorcar
{
public:
void yy2();
};
void motorcycle::yy2()
{
yy();
yy1();
}
void main()
{
motorcycle c;
c.yy2();
}
请按照题目,把我的程序改一下,并解释一下!要用我提到的函数做,别自己加函数和变量!
并且解释一下,这几句话什么意思!
c:\documents and settings\yinyue\桌面\cpp1.cpp(1) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\yinyue\桌面\cpp1.cpp(1) : error C2501: 'include' : missing storage-class or type specifiers
c:\documents and settings\yinyue\桌面\cpp1.cpp(1) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\yinyue\桌面\cpp1.cpp(3) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\yinyue\桌面\cpp1.cpp(3) : error C2447: missing function header (old-style formal list?)
c:\documents and settings\yinyue\桌面\cpp1.cpp(12) : error C2504: 'vehicle' : base class undefined
c:\documents and settings\yinyue\桌面\cpp1.cpp(19) : error C2504: 'vehicle' : base class undefined
先给10分,答的好我加分!
我调用run()和stop()是为了输出maxspeed,weight

第1个回答  2007-05-25
#include <iostream.h>
class vehicle
{
private:
int maxspeed;
int weight;
public:
void run()
{
cout<<"maxspeed"<<endl;
}
void stop()
{
cout<<"weight"<<endl;
}
};
class biycle:virtual public vehicle
{
private:
int height;
public:
void yy()
{
cout<<"height"<<endl;//修改的地方
run();
stop();
}
};
class motorcar:virtual public vehicle
{
private:
int seatsum;
public:
void yy1()
{
cout<<"seatsum"<<endl;//修改的地方
run();
stop();
}
};

class motorcycle:public biycle,public motorcar
{
public:
void yy2();
};
void motorcycle::yy2()
{
yy();
yy1();
}

int main()
{
motorcycle c;
c.yy2();
return 0;
}

你的include 没有#,而且cout输出变量值,run(),stop()没有返回值,不能用cout输出本回答被提问者采纳
相似回答