第1题:
试题六(共15分)
阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰( Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。
【java代码】
class invoice{
public void printInvoice(){:
System.out.println ( "This is the content of the invoice!");
}
}
class Decorator : extends Invoice {
protected Invoice ticket;
public Decorator(lnvoice t){
ticket = t;
}
public void printinvoice(){
if(ticket != NULL)
(1);
}
}
class FootDecorator extends Decorator{
public FootDecorator(lnvoice t){
super(t);
}
public void printinvoice (){
Systent.out.println( "This is the header of the invoice! ");
(2) ;
}
}
class FootDecorator extends Decorator {
public FootDecorator(invoice t):{
super(t);
}
public void printlnvoice(){
(3) ;
Systent.out.println( "This is the header of the invoice! ");
}
}
Class test {
public static void main(string[] args){
Invoice t =new invioce();
Invoice ticket;
Ticket= (4) ;
Ticket. Printinvoice();
Systent.out.println(“--------------“)
Ticket= (5) ;
Ticket. Printinvoice();
}
}
程序的输出结果为:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
第2题:
阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都
有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌
灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。command模式
的类图如图6-1所示。
【Java代码】
}
第3题:
●试题一
阅读下列说明和流程图,将应填入(n)的字句写在答题纸的对应栏内。
【说明】
下列流程图(如图4所示)用泰勒(Taylor)展开式
sinx=x-x3/3!+x5/5!-x7/7!+…+(-1)n×x 2n+1/(2n+1)!+…
【流程图】
图4
计算并打印sinx的近似值。其中用ε(>0)表示误差要求。
第4题:
阅读下列函数说明和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();
}
(1)
第5题:
(a)智能网概念模型中分布功能平面模型如下图所示,请根据此图将应填入(n)处的 字句写在答题纸的对应栏内。
第6题:
阅读以下说明和C++程序代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
在下面的C++代码中,类SalesTicket能够完成打印票据正文的功能,类HeadDec- orator与FootDecorator分别能够完成打印票据的台头和脚注的功能。
已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。
这是票据的台头!
这是票据正文!
这是票据的脚注!
---------------
这是票据的台头!
这是票据的脚注!
【C++程序代码】
#include
using namespace std;
class SalesTicket {
public:
(1) printTicket() { cout << " 是票据正文!" << endl;}
class Decorator : public SalesTicket{
SalesTicket *ticket;
public:
Decorator(SalesTicket *t){ ticket = t; }
void printTicket(){
if(ticket != NULL)
ticket->printTicket();
}
};
class HeadDecorator : public Decorator{
public:
HeadDecorator(SalesTicket *t): (2) { }
void printTicket() {
sour << "这是票据的台头!" << endl;
Decorator::printTicket();
}
};
class FootDecorator :public Decorator{
public:
FootDecorator(SalesTicket *t): (3)
void printTicket() {
Decorator::printTicket();
cout << "这是票据的脚注!" << endl;
}
};
void main(void) {
SalesTicket t;
FootDecorator f(&t);
HeadDecorator h( (4) );
h.printTicket();
cout << "-------------------------"<< endl;
FootDecorator a(NULL);
HeadDecorator b( (5) );
b.printTicket();
}
第7题:
第8题:
第9题:
第10题:
第11题:
第12题:
第13题:
阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都
有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌
灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。Command模式
的类图如图5-1所示。
【c++代码】
}
第14题:
●试题二
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
该程序运行后,输出下面的数字金字塔
【程序】
include<stdio.h>
main ()
{char max,next;
int i;
for(max=′1′;max<=′9′;max++)
{for(i=1;i<=20- (1) ;++i)
printf(" ");
for(next= (2) ;next<= (3) ;next++)
printf("%c",next);
for(next= (4) ;next>= (5) ;next--)
printf("%c",next);
printf("\n");
}
}
第15题:
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
第16题:
图2-1是基于软交换的网络分层模型。请将选项应填入(n)处的字句写在答题纸对应的解答栏内。
第17题:
图6-1是下一代网络的体系结构简图,请根据此简图将应填入(n)处的字句写在答题纸的对应栏内。
第18题:
第19题:
第20题:
第21题:
第22题:
第23题: