摘要:[C++代碼]#include<iostream>usingnamespace(1);classFlyBehavior{public:(2)fly()=0;};classQuackBehavior{public:(3)quack()=0;};classFlyWithWings:publicFlyBehavior{public:voidfly(){cout<<"使用翅膀飛行!"<<endl;}};classFlyNoWa
[C++代碼]
#include<iostream>
using namespace (1) ;
class FlyBehavior {
public : (2) fly() = 0;
};
class QuackBehavior {
public: (3) quack() = 0;
};
class FlyWithWings:public FlyBehavior{
public: void fly(){ cout << "使用翅膀飛行 !" << endl; }
};
class FlyNoWay:public FlyBehavior{
public: void fly(){ cout << "不能飛行 !" << endl; }
};
class Quack:public QuackBehavior{
public: void quack(){ cout << "發(fā)出\'嘎嘎\'聲 !" << endl; }
};
class Squeak:public QuackBehavior{
public: void quack(){ cout << "發(fā)出空氣與橡皮摩擦聲 !" << endl;
};
class QuackNoWay:public QuackBehavior{
public: void quack (){ cout << "不能發(fā)聲 !" << endl; }
};
class Duck {
protected:
FlyBehavior * (4) ;
QuackBehavior * (5) ;
public:
void fly(){ (6) ; }
void quack() { (7) ; };
virtual void display()=0;
};
class RubberDuck: public Duck {
public:
RubberDuck(){
flyBehavior = new (8) ;
quackBehavior = new (9) ;
}
~RubberDuck(){
if(!flyBehavior) delete flyBehavior;
if(!quackBehavior) delete quackBehavior;
}
void display(){ /*此處省略顯示橡皮鴨的代碼 */ }
};
//其它代碼省略
軟考備考資料免費(fèi)領(lǐng)取
去領(lǐng)取
共收錄117.93萬道題
已有25.02萬小伙伴參與做題