问题 填空题

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

[说明]

在销售系统中常常需要打印销售票据,有时需要在一般的票据基础上打印脚注。这样就需要动态地添加一些额外的职责。如下展示了Decorator(修饰)模式。SalesOrder对象使用一个SalesTicket对象打印销售票据,先打印销售票据内容,然后再打印脚注。图5-1显示了各个类间的关系。以下是C++语言实现,能够正确编译通过。

[图5-1]

[C++代码]

class Component{

public:

(1) void prtTicket()=0;

};

class SalesTicket:public Component{

public:

void prtTicket(){

cout<<"Sales Ticket!"<<endl;

}

};

class Decorator:public Component{

public:

virtual void prtTicket();

Decorator(Component *myC);

private:

(2) myComp;

};

Decorator::Decorator(Component *myC)

{

myComp=myC;

}

void Decorator::prtTicket()

{

myComp->prtTicket();

}

class Footer:public Decorator{

public:

Footer(Component *myC);

void prtTicket();

void prtFooter();

};

Footer::Footer(Component *myC): (3) {}

void Footer::prtFooter()

{

cout<<"Footer"<<endl;

}

void Footer::prtTicket()

{

(4)

prtFooter();

}

class SalesOrder{

public:

void prtTicket();

};

void SalesOrder::prtTicket()

{

Component *myST;

myST=new Footer( (5) );

myST->prtTicket();

}

(2)处填()。

答案

参考答案:Component*

口语交际,情景问答题
阅读理解

A water bearer in India had two large pots, each hung on each end of a pole which he carried across his neck. One of the pots had a crack(裂缝) in it, and while the other pot was perfect and always delivered a full portion of water at the end of the long walk from the stream to the master’s house, the cracked pot arrived only half full.

This went on daily. The perfect pot was proud of its accomplishment. Of course, the poor cracked pot was ashamed of its own imperfection. After two years of what it perceived to be a bitter failure, it spoke to the water bearer one day by the stream.

“I am ashamed of myself, and I want to apologise to you.”

“Why?” asked the bearer. “What are you ashamed of?”

“I have been able, for these past two years, to deliver only half my load because this crack in my side causes water to leak out all the way back. And you do no get full value for your efforts” the pot explained.

The water bearer felt sorry for the old cracked pot, and in his compassion he said, “As we return to the master’s house, I want you to notice the beautiful flowers along the path.”

As they went up the hill, the cracked pot took notice of the sun warming the beautiful wild flowers on the side of the path, and this cheered it a little.

The bearer said, “Did you notice that there were flowers only on your side of the path, but not on the other pot’s side?” That is because I have known about you, and I took advantage of it. I planted flower seeds on your side of the path, and every day while we walked back from the stream, you have watered them. For two years, I have been able to pick these beautiful flowers to decorate my master’s table. Without you being just the way you are, he would not have this beauty to grace his house.”

小题1:Why did the cracked pot feel ashamed?

A.Because it didn’t hold water.

B.Because the water bearer didn’t like it.

C.It couldn’t water the flowers well.

D.Because it could only accomplish half of its load.小题2:How would the cracked pot feel at the end of the story?

A.Delighted with itself.

B.Disappointed with itself.

C.Prouder than the other pot.

D.Still ashamed of itself.小题3:Which of the following is TRUE according to the passage?

A.There were flowers on both sides of the path.

B.The cracked pot was more useful than the perfect one.

C.We sometimes don’t have to mind too much the way we are.

D.The water bearer preferred the perfect pot to the cracked one.