一道C++一求解
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");
}
}