软题库 学习课程
当前位置:信管网 >> 在线考试中心 >> 信息系统项目管理师题库 >> 试题查看
试卷年份2016年下半年
试题题型【分析简答题】
试题内容

阅读下列说明和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 HeadDecorator extends Decorator{
public HeadDecorator(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 footnote 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!

查看答案

相关试题

3题: 阅读下列说明,回答问题1至问题3,将解答填入答题纸的对应栏内。
【说明】
某种出售罐装饮料的自动售货机( Vending Machine)的工作过程描述如下:
(1)顾客选择所需购买的饮料及数量。
(2)顾客从投币口向自动售货机中投入硬币(该自动售货机只接收硬币)。硬币器收集投入的硬币并计算其对应的价值。如果所投入的硬币足够购买所需数量的这种饮料且饮料数量足够,则推出饮料,计算找零,顾客取走饮料和找回的硬币;如果投入的硬币不够或者所选购的饮料数量不足,则提示用户继续投入硬币或重新选择饮料及数量。
(3)一次购买结束之后,将硬币器中的硬币移走(清空硬币器),等待下一次交易。自动售货机还设有一个退币按钮,用于退还顾客所投入的硬币。已经成功购买饮料的钱是不会被退回的。

现采用面向对象方法分析和设计该自动售货机的软件系统,得到如图3-1所示的用例图,其中,用例“购买饮料”的用例规约描述如下。 参与者:顾客。 主要事件流:
1.顾客选择需要购买的饮料和数量,投入硬币;
2.自动售货机检查顾客是否投入足够的硬币;
3.自动售货机检查饮料储存仓中所选购的饮料是否足够;
4.自动售货机推出饮料;
5.自动售货机返回找零。
各选事件流:
2a.若投入的硬币不足,则给出提示并退回到1;
3a.若所选购的饮料数量不足,则给出提示并退回到1 。
根据用例“购买饮料”得到自动售货机的4个状态:“空闲”状态、“准备服务”状态、“可购买”状态以及“饮料出售”状态,对应的状态图如图3-2所示。 所设计的类图如图3-3所示。


【问题1】(6分)
根据说明中的描述,使用说明中的术语,给出图3-2中的S1~S4所对应的状态名。
【问题2】(4分)
根据说明中的描述,使用说明中的术语,给出图3-2中的E1~E4所对应的事件名 。
【问题3】(5分)
根据说明中的描述,使用说明中的术语,给出图3-3中C1~C5所对应的类名。
答案解析与讨论:www.cnitpm.com/st/381716722.html

4题: 阅读下列说明和C代码,回答问题1至问题3,将解答写在答题纸的对应栏内。
【说明】
模式匹配是指给定主串t和子串s,在主串t中寻找子串s的过程,其中s称为模式。如果匹配成功,返回s在t中的位置,否则返回-1 。
KMP算法用next数组对匹配过程进行了优化。KMP算法的伪代码描述如下:
1.在串t和串s中,分别设比较的起始下标i=j=0。
2.如果串t和串s都还有字符,则循环执行下列操作:
(1)如果j=-l或者t[i]=s[j],则将i和j分别加1,继续比较t和s的下一个字符;
(2)否则,将j向右滑动到next[j]的位置,即j =next[j]。
3.如果s中所有字符均已比较完毕,则返回匹配的起始位置(从1开始);否则返回-1。其中,next数组根据子串s求解。求解next数组的代码已由get_next函数给出。
【C代码】
(1)常量和变量说明
t,s:长度为悯铂Is的字符串
next:next数组,长度为Is
(2)C程序
#include
#include
#include
/*求next[]的值*/
void get_next( int *next, char *s, int Is)  {
int i=0,j=-1;
next[0]=-1;/*初始化next[0]*/
while(i < ls){/*还有字符*/
if(j==-1l ls[i]==s[j]){/*匹配*/
j++;
i++;
if( s[i]==s[j])
next[i] = next[j];
else
Next[i] = j;

}
else
j = next[j];
}
}
int kmp( int *next, char *t ,char *s, int lt, int Is )
{
Int i= 0,j =0
while (i < lt && (1) ) {
if( j==-1 ||     (2)  )  {
i ++
j ++
} else
(3)
}
if (j >= ls)
return     (4)    else
return -1;
}
【问题1】(8分)
根据题干说明,填充C代码中的空(1)~(4)。
【问题2】(2分)
根据题干说明和C代码,分析出kmp算法的时间复杂度为(5)(主串和子串的长度分别为It和Is,用O符号表示)。
【问题3】(5分)
根据C代码,字符串“BBABBCAC”的next数组元素值为(6)(直接写素值,之间用逗号隔开)。若主串为“AABBCBBABBCACCD”,子串为“BBABBCAC”,则函数Kmp的返回值是(7)。
答案解析与讨论:www.cnitpm.com/st/3817229374.html

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

【C++代码】
#include
using namespace std;
class Invoice{ public:
(1)    {
cout<<"This is the content of the invoice!"< }
};
class Decorator : public Invoice {
Invoice *ticket;
public:
Decorator(lnvoice *t)      { ticket = t; }
void printInvoice(){
if(ticket != NULL)  (2);
}
};
class HeadDecorator : public Decorator{
public:
HeadDecorator(lnvoice*t): Decorator(t) { }
void printInvoice() {
cout<< "This is the header of the invoice! "<< endl;
(3)      ;
}
};
class FootDecorator : public Decorator{
public:
FootDecorator(Invoice *t): Decorator(t) { }
void printlnvoice(){
(4)   ;
cout<< "This is the footnote of the invoice!"<< endl;
}
};
int main(void) {
Invoice t;
FootDecorator f(&t);
HeadDecorator h(&f);
h.printInvoice();
cout<<”------------------------”< FootDecorator a(NULL)
HeadDecorator b(     (5)    );
b.printInvoice();
return 0;
}
程序的输出结果为:
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!
答案解析与讨论:www.cnitpm.com/st/3817318035.html