8、以下代码描述的是Moore型状态机: always @(in or state) case (state) zero: begin out = 0; if (in) next_state = one; else next_state = zero; end …………
第1题:
下面程序的输出结果是( )。 public class Sun { public static void main(String args[ ]) { int i = 1; switch (i) { case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2; System.out.println("two"); default: System.out.println("default"); } } }
A.one
B.one,default
C.one,two,default
D.default
第2题:
以下程序的输出结果为【 】。
include<iostream>
using namespace std;
void initialize(int printNo,int state=0);
void initialize(int printNo=l,int state);
int main()
{
initialize();
return 0;
}
void initialize(int printNo,int state)
{
cout<<printNo<<","<<state<<end1;
}
第3题:
下面程序的输出结果是( )。 public class Sun { public static void main(String args[ ]) { int i = 1; switch (i) { case 0: System.but.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); default: System.out.println ("default"); } } }
A.one
B.one, default
C.one, two, default
D.default
第4题:
下列语句能给数组赋值而不使用for循环的是
A.myArray{[1]="One";[2]="Two";[3]="Three";}
B.String s[5]=new String[]{"Zero", "One", "Two", "There", "Four"};
C.String s[]=new String[]{"Zero", "One", "Two", "There", "Four"};
D.String s[]=new String[]=|"Zero", "One", "Two", "There", "Four"};
第5题:
下面程序的输出结果为【 】。
include <iostream>
using namespace std;
void initialize(int printNo,int state=0);
void initialize(int printNo=1,int state);
int main()
{
initialize();
return 0;
}
void initialize(int printNo, int state)
{
cout<<printNo<<","<<state<<end1;
}
第6题:
请认真阅读以下关于某传输系统的技术说明、状态转换图及C++代码,根据要求回答问题1和问题2。
【说明】
传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening(正在打开)、StayOpen(保持打开)和Closing(正在关闭)5种状态。触发状态的转换事件有click、complete和timeout 3种,事件与其相应的状态转换如图6-18所示。
下面的【C++代码1】与【C++代码2】分别用两种不同的设计思路对传输门进行状态模拟,请填补代码段中的空缺语句。
【C++代码1】
const int CLOSED = 1; const int PENING = 2;
const int PEN = 3; const int CLOSING = 4;
const int STAYOPEN = 5; //定义状态变量,用不同整数表示不同状态
class Door {
private:
private:
int state; //传输门当前状态
void setState(int state) { this->state = stale; } //设置当前状态
public:
Door () :state (CLOSED) { };
void getState() { //根据当前状态输出相应的字符串
switch(state) {
case OPENING: cout <<"OPENING" << endl; break;
case CLOSED: cout << "CLOSED" << endl; break;
case OPEN: cout << "OPEN" << endl; break;
case CLOSING: cout << "CLOSING" << endl; break;
case STAYOPEN: cout << "STAYOPEN" << endl; break;
}
}
void click() { //发生click事件时进行状态转换
if ( (1) ) setState(OPENING);
else if ( (2) ) setState(CLOSING);
else if ( (3) ) setState(STAYOPEN);
}
void timeout() { //发生timeout事件时进行状态转换
if (state == OPEN) setState(CLOSING);
}
void complete() { //发生complete事件时进行状态转换
if (state == OPENING) setState(OPEN);
else if (state == CLOSING) setState(CLOSED);
}
};
int main(){
Door aDoor;
aDoor.getState(); aDoor.click(); aDoor.getState(); aDoor.complete();
aDoor.getState(); aDoor.click(); aDoor.getState(); aDoor.click();
aDoor.getState(); return 0;
}
【C++代码2】
class Door {
public:
DoorState *CLOSED, *OPENING, *OPEN, *CLOSING, *STAYOPEN, *state;
Door();
virtual ~Door() { ... //释放申请的内存,此处代码省略};
void s
第7题:
下列语句能给数组赋值,而不使用for循环的是
A.myArray{[1]="One";[2]="Two";[3]="Three";}
B.String s[5]=new String[] {"Zero","One","Two","Three","Four"};
C.String s[]=new String[] {"Zero","One","Two","Three","Four"};
D.String s[]=new String[]= {"Zero","One","Two","Three","Four"};
第8题:
针对以下程序段,对于变量c的取值,至少需要(61)个测试用例才能够满足语句覆盖的要求。c=((u8_t*)q->payload)[i];switch(c){case SLIP_END: sio_send(SLIP_ESC,netif->state); sio_send(SLIP_ESC_END,netif->state); break;case SLIP_ESC: sio_send(SLIP_ESC,netif->state); sio_send(SLIP_ESC_ESC,netif->state); break;default: sio_send(c,netif->state); break; }
A.4
B.3
C.2
D.1
第9题:
有如下代码段:
switch ( x ){
case 1:System.out.println("One");break;
case 2:
case 3:System.out.println("Two");break;
default:System.out.println("end");
}
变量x的取值下列哪些情形时,能使程序输出"Two" 。
A. 1
B. 2
C. 3
D. default
第10题:
英语中号码“96100”的表示方法是“()”。
第11题:
public static void main(String[]args){ String str="null"; if(str==null){ System.out.println("null"); }else(str.length()==0){ System.out.println("zero"); }else{ System.out.println("some"); } } What is the result?()
第12题:
null
zero
some
Compilation fails.
An exception is thrown at runtime.
第13题:
此题为判断题(对,错)。
第14题:
A.null
B.zero
C.some
D.Compilationfails.
E.Anexceptionisthrownatruntime.
第15题:
编译和执行以下代码,输出结果是( )。 int i=1; switch (i) { case 0: System.out.print("zero,"); break; case 1: System.out.print("one,"); case 2: System.out.print("two,"); default: System.out.println("default"); }
A.one,
B.one,two,
C.one,two,default
D.default
第16题:
阅读以下说明和C++代码。
【说明】
传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening (正在打开)、StayOpen(保持打开)和Closing(正在关闭)五种状态。触发传输门状态转换的事件有click、complete和timeout三种。事件与其相应的状态转换如下图所示。
下面的C++代码1与C++代码2分别用两种不同的设计思路对传输门进行状态模拟,请填补代码中的空缺。
【C++代码1】
const int CLOSED=1; const int PENING=2;
const int PEN=3; const int CLOSING=4;
const int STAYOPEN=5; //定义状态变量,用不同整数表示不同状态
class Door {
Private:
int state; //传输门当前状态
void setState(int state){ this->state=state;} //设置当前状态
public:
Door():state(CLOSED){};
void getState(){ //根据当前状态输出相应的字符串
switch(state){
case OPENING: cout<<"OPENING"<<endl; break;
case CLOSED: cout<<"CLOSED"<<endl; break;
case OPEN: cout<<"OPEN"<<endl; break;
case CLOSING: cout<<"CLOSING"<<endl; break;
case STAYOPEN:cout<<"STAYOPEN"<<endl; break;
}
};
void click() { //发生click事件时进行状态转换
if ((1)) setState(OPENING);
else if ((2)) setState(CLOSING);
else if ((3)) setState(STAYOPEN);
}
void timeout(){ //发生timeout事件时进行状态转换
if (state == OPEN) setState(CLOSING);
}
void complete(){ //发生complete事件时进行状态转换
if (state == OPENING) setState(OPEN);
else if (state == CLOSING) setState(CLOSED);
}
};
int main(){
Door aDoor;
aDoor.getState();aDoor.click(); aDoor.getState();
aDoor.complete();aDoor.getState(); aDoor.click();
aDoor.getState();aDoor.click(); aDoor.getState(); return 0;
}
【C++代码2】
class Door {
public:
DoorState *CLOSED,*OPENING,*OPEN,*CLOSING,*STAYOPEN,*state;
Door();
virtual~Door(){……//释放申请的内存,此处代码省略);
void setState(DoorState *state) { this->state = state;}
void getState(){
//此处代码省略,本方法输出状态字符串,
//例如,当前状态为CLOSED时,输出字符串为“CLOSED”
};
void click();
void timeout();
void complete();
};
Door::Door(){
CLOSED = new DoorClosed(this); OPENING = new DoorOpening(this);
PEN = new DoorOpen(this); CLOSING = new DoorClosing(this);
STAYOPEN = new DoorStayOpen(this);state = CLOSED;
}
void Door :: click() {(4);)
void Door :: timeout() {(5);)
void Door :: complete() {(6);}
class DoorState//定义一个抽象的状态,它是所有状态类的基类
{
protected:Door *door;
public:
DoorState(Door *door) {this->door = door;}
virtual~DoorState(void);
virtual void click() {}
virtual void complete(
第17题:
以下语句正确的是:______。
A.Select Case a Case b=1 Case “B” b=2 Case Else b=3 End Select
B.Select Case a Case “A” b=1 Case “B” b=2 Case Default b=3 End Select
C.Switch a Case “A” b=1 Case “B” b=2 Case Else b=3 End Switch
D.Switch a Case “A” b=1 Case “B” b=2 Case Default b=3 End Select
第18题:
运行下列程序: x=InputBox("input value of x") Select Case X Case Is>0 y=y+1 Case Is=0 y=x+2 Case ELse y=x+3 End Select Print x;y 运行时,从键盘输入-5,输出的结果是( )。
A.-7
B.-9
C.-8
D.-10
第19题:
有如下程序: x = InputBox("Input value of x") Select Case x Case Is > 0 y=y+1 Case Is = 0 y=x + 2 Case Else y=x + 3 End Select Print x, y运行时,从键盘输入-5,输出的结果是( )。
A.-7
B.-9
C.-8
D.-10
第20题:
以下代码段的输出结果为
1. int x = 0, y = 4, z = 5;
2. if (x >2、{
3. if (y<5、{
4. System. out .println ( "message one" );
5. }
6. else {
7. System.out.println( "message two");
8. }
9. }
10. else if (z >5、{
11. System.out.println("message three");
12. }
13. else {
14. System.out.println( "message four");
15. }
A. message one
B. message two
C. message three
D. message four
第21题:
public static void main(String[] args) { String str = “null‟; if (str == null) { System.out.println(”null”); } else (str.length() == 0) { System.out.println(”zero”); } else { System.out.println(”some”); } } What is the result?()
第22题:
下列对条件语句、分支语句、固定循环次数语句、不定循环次数语句关键字排序正确的是()
第23题:
if elseend;for end;switch case end;while end;
if elseend;switch case end;for end;while end;
for end;if else end;while end;switch case end;
while end;for end;switch case end;if else end;
第24题:
null
zero
some
Compilationfails.
Anexceptionisthrownatruntime.