一道C++一求解

来源:百度知道 编辑:UC知道 时间:2024/05/05 02:48:02
double getspeed{
switch(_type)
case EURPEAN:return getbasespeed();
case AFRICA:return getbasespeed()+exraspeed()+coslt;
throw RuntimeExcption(prinrf("no ***!))
}
程序大概是这样个意思,可能有错误,要求面向对象的c++重写他(超类可定义为bird)
谢了先
谢了,不过既然说了超类的事实不是里买应该有继承的类阿?

class Bird
{
public:
enum TYPE{ EURPEAN = 1, AFICA};
Bird() : bspeed(0.), espeed(0.), coslt(0.), type(0){}
double GetSpeed();
double GetBaseSpeed() const{ return bspeed; }
double Exraspeed() const { return espeed; }
void SetBaseSpeed(double bs){ bspeed = bs; }
void SetExraSpeed(double es){ espeed = es; }
void SetCoslt(double cs) { coslt = cs; }
void SetType(TYPE tp) { type = tp; }

private:
int type;
double bspeed;
double espeed;
double coslt;
};

inline double Bird::GetSpeed()
{
switch(type)
{
case EURPEAN:
return GetBaseSpeed();
case AFRICA:
return GetBaseSpeed() + GetExraSpeed() + coslt;
default:
throw string("No the Type");
}
}

定义个类...
创建个对象..
把那些写进去...
就OK了