niusouti.com

阅读以下说明和C++代码(代码13-1),将应填入(n)处的字句写在对应栏内。【说明】软件设计师东方飞龙利用UML设计了一个迷你小型复数类,其类图如图13-11所示。【代码13-l】/*___________________________________*//********* 文件 MiniComplex. h*********//*___________________________________*/include<iostream>using namespace std;class MiniC

题目

阅读以下说明和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】/*_____________”相关问题
  • 第1题:

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




    【问题1】(15分)阅读上述说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。


    答案:
    解析:
    注意:原版的题目应该是Cbasic、CSilve。(1) virtual double travel(int miles,FrequentFlyer* context)=0(2)context->setState(context->Cbasic)(3)context->setState(context->CSilve)(4)context->setState(context->Cbasic)(5)context->setState(context->CSilve)

  • 第2题:

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



    答案:
    解析:
    1: void update()2: Observer3: obs.update()4: Subject5: Attach(this)

  • 第3题:

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






    答案:
    解析:

  • 第4题:

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




    答案:
    解析:
    1.void stop()2.BrakeBehavior3.wheel.stop()4.wheel=behavior5.brake()

  • 第5题:

    阅读下列说明和 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& s) { PartA = s;}
    ???? void setPartB(const string& s) { PartB
    = s;}? ?
    //? 其余代码省略
    };
    class Builder {
    public:? ? ??
    (1)??
    ;?
    virtual void buildPartB()=0;? ? ?
    (2)??
    ;
    };
    class ConcreteBuilder1 : public Builder {
    private:?
    Product*?? product;
    public:
    ConcreteBuilder1() {product = new Product();???? }
    void buildPartA() {????? (3)???? ("Component
    A"); }?
    void buildPartB() {????? (4)???? ("Component
    B"); }??
    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 = new
    Director(new ConcreteBuilder1());
    ???????????????? director1.construct();? ? ? ??
    }


    答案:
    解析:
    (1)void buildPart A()
    (2) Product getResult()
    (3)product.setPartA
    (4)product.setPartB
    (5)builder.buildPartA();
    builder.buildPartB();
    Product p=builder.getResult();