问题 选择题

根据下表信息,下列叙述中正确的是(  )

  序号  氧化剂  还原剂氧化产物还原产物
  ①    Cl2  FeBr2  FeCl3
  ②  KMnO4  H2O2    O2  MnO2
  ③  KClO3  浓盐酸    Cl2
  ④  KMnO4  浓盐酸    Cl2  MnCl2

A.表中①反应的氧化产物只能有FeCl3

B.表中②生成1mol的O2将有4mol的电子转移

C.表中④的离子方程式配平后,H+的化学计量数为16

D.表中③还原产物是KCl

答案

A.氯气具有强氧化性,可氧化Fe2+和Br-,氧化产物有FeCl3和Br2,故A错误;

B.H2O2中O元素化合价由-1价升高到0价,表中②生成1mol的O2将有2mol的电子转移,故B错误;

C.表中④的离子方程式为2MnO4-+16H++10Cl-=2Mn2+↑+5C12↑+8H2O,H+的化学计量数为16,故C正确;

D.表中③Cl2既是氧化产物又是还原产物,KCl由HCL生成,化合价没有发生变化,故D错误.

故选C.

问答题

【说明】
传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening(正在打开)、StayOpen(保持打开)和Closing(正在关闭)5种状态。触发状态的转换事件有click、complete和timeout 3种,事件与其相应的状态转换如图6-18所示。


下面的【C++代码1】与【C++代码2】分别用两种不同的设计思路对传输门进行状态模拟,请填补代码段中的空缺语句。
【C++代码1】
const int CLOSED = 1; const int OPENING = 2;
const int OPEN = 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 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);
OPEN = 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()
virtual void timeout()
;
class DoorClosed :public DoorState //定义一个基本的closed状态
public:
DoorClosed(Door *door):DoorState(door)
virtual ~ DoorClosed ()
void click();
;
void DoorClosed::click() (7) ;
//其他状态类的定义与实现代码省略
iht main()
Door aDoor;
aDoor.getState(); aDoor.click(); aDoor.getState(); aDoor.complete();
aDoor.getState(); aDoor.timeout(); aDoor.getState(); return 0;

【问题2】
请用150字以内的文字简要说明【C++代码1】、【C++代码2】这两种对传输门进行状态模拟的设计思路的区别之处。

单项选择题