阅读以下说明和C++代码(代码13-1),将应填入(n)处的字句写在对应栏内。【说明】软件设计师东方飞龙利用UML设计了一个迷你小型复数类,其类图如图13-11所示。【代码13-l】/*___________________________________*//********* 文件 MiniComplex. h*********//*___________________________________*/include<iostream>using namespace std;class MiniComplex{(1)://重载流插入和提取运算符(2) ostream operator <<(ostream osObject, const MiniComplex complex){ osObject <<"("<<complex. realPart<<"+"<<complex. imagPart <<"I"<<")";return osObject;}friend (3) operator >>(istream isObject, MiniComplex complex){ char ch;isObject >>complex. realPart >>ch>>complex. imagPart >>ch;return isObject;}MiniComplex(double real=0, double imag=0); //构造函数MiniComplex operator+(const MiniComplex otherComplex)const! //重载运算符+MiniComplex operator--(const MiniComplex otherComplex)const! //重载运算符-MiniComplex operator*(const MiniComplex othmComplex)const; //重载运算符*MiniComplex operator/(const MiniComplex otherComplex)const; //重载运算符/bool perator==(const MiniComplex otherComplex)const; //重载运算符==private:double realPart; //存储实部变量double imagPart; //存储虚部变量};/*_______________________________________________________*//* * * * * * * * *文件 MiniComplex. cpp* * * * * * * * * *//*_______________________________________________________*/include "MiniComplex.h"bool MiniComplex:: perator==(const MiniComplex otherComplex)const{ (1);}MiniComplex:: MiniComplex(double real, double imag){realPart=real;imagPart=imag!}MiniComplex MiniComplex:: operator+(const MiniComplex otherComplex)const{ MiniComplex temp;temp. realPart=realPart+ otherComplex. realPart;temp. imagPart=imagPart+ otherComplex. imagPart;return temp;}MiniComplex MiniComplex::operator--(const MiniComplex otherComplex)const{ MiniComplex temp;temp.realPart=realPart-otherComplex.realPart;temp. imagPart=imagPart-otherCompler.imagPart;return temp;}MiniComplex MiniComplex:: operator*(const MiniComplex otherComplex)const{ MiniComplex temp;temp.realPart=(realPart* otherComplex.realPart)-(imag-Part* otherComplex.imag-Part);temp imagPart=(realPart* otherComplex. imagPart)+(imag-Part *otherComplex.realPart);return temp,}MiniComplex MiniComplex:: operator/(const MiniComplex otherComplex)eonst{ MiniComplex temp;float tt;tt=1/(otherComplex. realPart *otherComplex. realPart+otherComplex. imagPart* other Complex.imagPart);temp. realPart=((realPart* otherComplex.realPart)+(imagPart* otherComplex.imagPart))*tt;temp. imagPart=((imagPart * otherComplex.realPart)-(realPart* otherComplex.imagPart))*tt;

阅读以下说明和C++代码(代码13-1),将应填入(n)处的字句写在对应栏内。

【说明】

软件设计师东方飞龙利用UML设计了一个迷你小型复数类,其类图如图13-11所示。

【代码13-l】

/*___________________________________*/

/********* 文件 MiniComplex. h*********/

/*___________________________________*/

include<iostream>

using namespace std;

class MiniComplex

{(1):

//重载流插入和提取运算符

(2) ostream & operator <<(ostream & osObject, const MiniComplex & complex)

{ osObject <<"("<<complex. realPart<<"+"<<complex. imagPart <<"I"<<")";

return osObject;

}

friend (3) operator >>(istream & isObject, MiniComplex & complex)

{ char ch;

isObject >>complex. realPart >>ch>>complex. imagPart >>ch;

return isObject;

}

MiniComplex(double real=0, double imag=0); //构造函数

MiniComplex operator+(const MiniComplex & otherComplex)const! //重载运算符+

MiniComplex operator--(const MiniComplex & otherComplex)const! //重载运算符-

MiniComplex operator*(const MiniComplex& othmComplex)const; //重载运算符*

MiniComplex operator/(const MiniComplex & otherComplex)const; //重载运算符/

bool perator==(const MiniComplex &otherComplex)const; //重载运算符==

private:

double realPart; //存储实部变量

double imagPart; //存储虚部变量

};

/*_______________________________________________________*/

/* * * * * * * * *文件 MiniComplex. cpp* * * * * * * * * */

/*_______________________________________________________*/

include "MiniComplex.h"

bool MiniComplex:: perator==(const MiniComplex & otherComplex)const

{ (1);}

MiniComplex:: MiniComplex(double real, double imag){realPart=real;imagPart=imag!}

MiniComplex MiniComplex:: operator+(const MiniComplex & otherComplex)const

{ MiniComplex temp;

temp. realPart=realPart+ otherComplex. realPart;

temp. imagPart=imagPart+ otherComplex. imagPart;

return temp;

}

MiniComplex MiniComplex::operator--(const MiniComplex & otherComplex)const

{ MiniComplex temp;

temp.realPart=realPart-otherComplex.realPart;

temp. imagPart=imagPart-otherCompler.imagPart;

return temp;

}

MiniComplex MiniComplex:: operator*(const MiniComplex& otherComplex)const

{ MiniComplex temp;

temp.realPart=(realPart* otherComplex.realPart)-(imag-Part* otherComplex.imag-Part);

temp imagPart=(realPart* otherComplex. imagPart)+(imag-Part *otherComplex.realPart);

return temp,

}

MiniComplex MiniComplex:: operator/(const MiniComplex& otherComplex)eonst

{ MiniComplex temp;

float tt;

tt=1/(otherComplex. realPart *otherComplex. realPart+otherComplex. imagPart* other Complex.imagPart);

temp. realPart=((realPart* otherComplex.realPart)+(imagPart* otherComplex.imagPart))*tt;

temp. imagPart=((imagPart * otherComplex.realPart)-(realPart* otherComplex.imagPart))*tt;<


相关考题:

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。Command模式的类图如图5-1所示。【c++代码】}

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。command模式的类图如图6-1所示。【Java代码】}

阅读下列说明和 C ++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 6-1 所示。【C++ 代码】#includeusing namespace std;class BrakeBehavior{public:(1) ; /*其余代码省略*/};class LongWheelBrake : public BrakeBehavior{public:void stop(){cout

阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

阅读下列说明和C++代码,回答问题,将解答填入答题纸的对应栏内。【说明】某航空公司的会员积分系统将其会员划分为:普卡 (Basic)、银卡(Silver)和金卡 (Gold) 三个等级。非会员 (NonMember) 可以申请成为普卡会员。会员的等级根据其一年内累积 的里程数进行调整。描述会员等级调整的状态图如图 5-1 所示。现采用状态 (State) 模式实现上述场景,得到如图 5-2 所示的类图。【问题1】(15分)阅读上述说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

阅读下列说明和 Java 代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上 留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy) 设 计模式来实现该需求,所设计的类图如图 5-1 所示。

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 某文件管理系统中定义了类OfficeDoc和DocExplorer,当类OfficeDoc发生变化时,类DocExplorer的所有对象都要更新其自身的状态,现采用观察者(Observer)设计模式来实现该需求,所设计的类图如图6-1所示。

阅读下列说明和 Java 代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图 6-1 所示为其类图。阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】???? 生成器(Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图5-1所示为其类图。?【C++代码】#include #include using namespace std;class Product {private:?string partA, partB;public:?Product() {?? }? ?void setPartA(const string}???? void setPartB(const string}? ?//? 其余代码省略};class Builder {public:? ? ??(1)??;?virtual void buildPartB()=0;? ? ?(2)??;};class ConcreteBuilder1 : public Builder {private:?Product*?? product;public:ConcreteBuilder1() {product = new Product();???? }void buildPartA() {????? (3)???? ("ComponentA"); }?void buildPartB() {????? (4)???? ("ComponentB"); }??Product* getResult() { return product; }//? 其余代码省略};class ConcreteBuilder2 : public Builder {? ??? ? ? ?/*??? 代码省略??? */};class Director {private:? ??Builder* builder;public:??Director(Builder* pBuilder) { builder= pBuilder;}? ??void construct() {????????????????? (5)???? ;?????????????? //? 其余代码省略? ?}??//? 其余代码省略};int main() {? ? ??Director* director1 = new Director(new ConcreteBuilder1());? ?director1->construct();? ? ??delete director1;? ? ?return 0;【Java代码】import jav(6)A.util.*;class Product {? ? ? ?private String partA;? ? ? ?private String partB;? ? ? ??public Product() {}? ? ??public void setPartA(String s) { partA = s; }? ? ? ?public void setPartB(String s) { partB = s; }}interface Builder {? ?public?????? (1)???? ;? ??public void buildPartB();? ? ??public?????? (2)???? ;}class ConcreteBuilder1 implements Builder {? ? ? ?private Product product;? ? ? ?public ConcreteBuilder1() { product = new Product();?? }? ? ? ??public void buildPartA() {????????(3)??("Component A"); }public void buildPartB() {???? ????(4)?? ("Component B"); }? ? ??public Product getResult() { return product;}}class ConcreteBuilder2 implements Builder {?? ? ? ? ?//? 代码省略}class Director {? ? ? ?private Builder builder;? ? ? ?public Director(Builder builder) {this.builder = builder; }public void construct() {? ? ? ? ? ? ? ? ? (5)???? ;? ? ? ? ? ? ? //? 代码省略? ? ??}}class Test {? ? ??public static void main(String[] args) {???????????????? Director director1 = newDirector(new ConcreteBuilder1());???????????????? director1.construct();? ? ? ??}

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。【说明】某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。