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

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

【Java代码】
class Light {
public Light() {}
public Light(String name) { /* 代码省略 */ }
public void on()  { /* 代码省略 */ }    // 开灯
public void off()  { /* 代码省略 */ }    // 关灯
// 其余代码省略
}
(1)     {
public void execute();
}
class LightOnCommand implements Command { // 开灯命令
Light light;
public LightOnCommand(Light light) { this.light=light; }
public void execute() {     (2)    ; }
}
class LightOffCommand implements Command { // 关灯命令
Light light;
public LightOffCommand(Light light) { this.light=light; }
public void execute(){     (3)    ; }
}
class RemoteControl { // 遥控器
Command[] onCommands=new Command[7];
Command[] offCommands=new Command[7];
public RemoteControl() { /* 代码省略 */ }
public void setCommand(int slot, Command onCommand, Command offCommand) {
(4)    =onCommand;
(5)    =offCommand;
}
public void onButtonWasPushed(int slot) {
(6)    ;
}
public void offlButtonWasPushed(int slot){
(7)    ;
}
}
class RemoteLoader {
public static void main(String[] args) {
RemoteControl remoteControl=new RemoteControl();
Light livingRoomLight=new Light("Living Room");
Light kitchenLight=new Light("kitchen");
LightOnCommand livingRoomLightOn=new LightOnCommand(livingRoomLight);
LightOffCommand livingRoomLightOff=new LightOffCommand(livingRoomLight);
LightOnCommand kitchenLightOn=new LightOnCommand(kitchenLight);
LightOffCommand kitchenLightOff=new LightOffCommand(kitchenLight);
remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
remoteControl.onButtonWasPushed(0);
remoteControl.offButtonWasPushed(0);
remoteControl.onButtonWasPushed(1);
remoteControl.offButtonWasPushed(1);
}
}

查看答案

相关试题

3题: 阅读下列说明和图,回答问题1至问题3,将解答填入答题纸的对应栏内。
【说明】
某公司欲开发一个管理选民信息的软件系统。系统的基本需求描述如下:
(1)每个人(Person)可以是一个合法选民(Eligible)或者无效的选民(Ineligible)。
(2)每个合法选民必须通过该系统对其投票所在区域(即选区,Riding)进行注册( Registration)。每个合法选民仅能注册一个选区。
(3)选民所属选区由其居住地址(Address)决定。假设每个人只有一个地址,地址可以是镇(Town)或者城市(City)。
(4)某些选区可能包含多个镇;而某些较大的城市也可能包含多个选区。
现采用面向对象方法对该系统进行分析与设计,得到如图1-1所示的初始类图。

【问题1】 (8分)
根据说明中的描述,给出图1-1中C1~C4所对应的类名(类名使用说明中给出的英文词汇)。
【问题2】(3分)
根据说明中的描述,给出图1-1中M1~M6处的多重度。
【问题3】(4分)
现对该系统提出了以下新需求:
(1)某些人拥有在多个选区投票的权利,因此需要注册多个选区;
(2)对手满足(1)的选民,需要划定其“主要居住地”,以确定他们应该在哪个选区进行投票。
为了满足上述需求,需要对图1-1所示的类图进行哪些修改?请用100字以内文字说明。
答案解析与讨论:www.cnitpm.com/st/3814720120.html

4题: 阅读下列说明和C代码,回答问题1至问题3,将解答写在答题纸的对应栏内。
【说明】
计算一个整数数组a的最长递增子序列长度的方法描述如下:
假设数组a的长度为n,用数组b的元素b[i]记录以a[i](0≤i;其中b[i]满足最优子结构,可递归定义为:

【C代码】
下面是算法的C语言实现。
(1)常量和变量说明
a:长度为n的整数数组,待求其最长递增子序列
b:长度为n的数组,b[i]记录以a[i](0≤i度,其中0≤ilen:最长递增子序列的长度
i,j:循环变量
temp:临时变量
(2)C程序
#include
int maxL(int*b, int n) {
int i, temp=0;
for(i=0; i if(b[i]>temp)
temp=b[i];
}
return temp;
}
int main() {
int n, a[100], b[100], i, j, len;
scanf("%d", &n);
for(i=0; i scanf("%d", &a[i]);
}
(1)    ;
for(i=1; i for(j=0, len=0;     (2)    ; j++) {
if(    (3)     && len len=b[j];
}
(4)    ;
}
Printf("len:%d\n", maxL(b,n));
printf("\n");
}
【问题1】(8分)
根据说明和C代码,填充C代码中的空(1)~(4)。
【问题2】(4分)
根据说明和C代码,算法采用了 (5) 设计策略,时间复杂度为 (6) (用O符号表示)。
【问题3】(3分)
已知数组a={3,10,5,15,6,8},根据说明和C代码,给出数组b的元素值。
答案解析与讨论:www.cnitpm.com/st/3814829334.html

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

【C++代码】
class Light {
public:
Light(string name) { /* 代码省略 */ }
void on() { /* 代码省略 */ }    // 开灯
void off() { /* 代码省略 */ }  // 关灯
};
class Command {
public:
(1)    ;
};
class LightOnCommand:public Command { // 开灯命令
private:
Light* light;
public:
LightOnCommand(Light* light) { this->light=light; }
void execute() {     (2)    ; }
};
class LightOffCommand:public Command { // 关灯命令
private:
Light *light;
public:
LightOffCommand(Light* light) { this->light=light; }
void execute() {     (3)    ; }
};
class RemoteControl{ // 遥控器
private:
Command* onCommands[7];
Command* offCommands[7];
public:
RemoteControl() { /* 代码省略 */ }
void setCommand(int slot, Command* onCommand, Command* offCommand) {
(4)    =onCommand;
(5)    =offCommand;
}
void onButtonWasPushed(int slot) {     (6)    ; }
void offButtonWasPushed(int slot) {     (7)    ; }
};
int main() {
RemoteControl* remoteControl=new RemoteControl();
Light* livingRoomLight=new Light("Living Room");
Light* kitchenLight=new Light("kitchen");
LightOnCommand* livingRoomLightOn=new LightOnCommand(livingRoomLight);
LightOffCommand* livingRoomLightOff=newLightOffCommand(livingRoomLight);
LightOnCommand* kitchenLightOn=new LightOnCommand(kitchenLight);
LightOffCommand* kitchenLightOff=new LightOffCommand(kitchenLight);
remoteControl->setCommand(0, livingRoomLightOn, livingRoomLightOff);
remoteControl->setCommand(1, kitchenLightOn, kitchenLightOff);
remoteControl->onButtonWasPushed(0);
remoteControl->offButtonWasPushed(0);
remoteControl->onButtonWasPushed(1);
remoteControl->offButtonWasPushed(1);
/* 其余代码省略 */
return 0;
}
答案解析与讨论:www.cnitpm.com/st/3814921042.html