View on GitHub

Homework Space

Homework Space for Introduction to Software Engineering

第八次作业

第一部分-阅读

阅读 Pseudocode Standard。(答案可以打印)
1)用伪代码描述将十进制转换成16进制的方法
接收传入数
设乘数为1,十六进制结果为0
IF 数字<0 THEN
记下-号,数字取反;
ENDIF
REPEAT
分别取数除以16的余数与商
结果加上余数与乘数的乘积,乘数乘以16
将商赋值给数
UNTIL 数等于0
将结果返回

2)C语言实现(先用注释写好算法,然后翻译)

(这里使用的C++,为方便使用栈加字符串进行结果运算)
3)使用 -1, 0, 1, 15, 26,3265 最为输入测试你的程序

第二部分-名词解释

名词解释与对比
1)Top-down design A top-down approach (also known as stepwise design and in some cases used as a synonym of decomposition) is essentially the breaking down of a system to gain insight into its compositional sub-systems in a reverse engineering fashion. In a top-down approach an overview of the system is formulated, specifying, but not detailing, any first-level subsystems. Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. A top-down model is often specified with the assistance of “black boxes”, which makes it easier to manipulate. However, black boxes may fail to clarify elementary mechanisms or be detailed enough to realistically validate the model. Top down approach starts with the big picture. It breaks down from there into smaller segments.
2) Work breakdown structure (WBS) A work-breakdown structure (WBS) in project management and systems engineering, is a deliverable-oriented breakdown of a project into smaller components. A work breakdown structure is a key project deliverable that organizes the team’s work into manageable sections. The Project Management Body of Knowledge (PMBOK 5) defines the work-breakdown structure “A hierarchical decomposition of the total scope of work to be carried out by the project team to accomplish the project objectives and create the required deliverables.”
3)简述管理学 WBS 与 信息学Top-down设计 的异同
异:Top-down是从上往下拆分,而WBS是按照类型拆分
同:都可以将大任务拆分成很多的部分。

第三部分-洗衣机算法

仔细观察您洗衣机的运作过程,运用Top-down设计方法和Pseudocode 描述洗衣机控制程序。假设洗衣机可执行的基本操作如下:
water_in_switch(open_close) // open 打开上水开关,close关闭
water_out_switch(open_close) // open 打开排水开关,close关闭
get_water_volume() //返回洗衣机内部水的高度
motor_run(direction) // 电机转动。left左转,right右转,stop停
time_counter() // 返回当前时间计数,以秒为单位
halt(returncode) //停机,success 成功 failure 失败
1)请使用伪代码分解“正常洗衣”程序的大步骤。包括注水、浸泡等

  1. 按下启动键,选择水位,选择时间
  2. 注水到预定水位
  3. 浸泡到预定时间
  4. 漂洗,电机转动, 每周期左转3次,右转3次
  5. 排水
  6. 脱水,电机转动
  7. 结束

2)进一步用基本操作、控制语句(IF、FOR、WHILE等)、变量与表达式,写出每个步骤的伪代码

  1. READ waterLine,timeLine1, timeLine2
  2. REPEAT
    water_in_switch(open)
    UNTIL get_water_volume==waterLine
    water_in_switch(close)
  3. REPEAT
    浸泡
    UNTIL time_counter()==timeLine1
  4. SET nowTime = time_counter()
    REPEAT
    SET tempTime1 = time_counter()
    REPEAT
    motor_run(left)
    UNTIL time_counter()-tempTime1==3 SET tempTime2 = time_counter()
    REPEAT
    motor_run(right)
    UNTIL time_counter()-tempTime2==3
    motor_run(stop)
    UNTIL time_counter()-nowTime==timeLine2
  5. REPEAT
    water_out_switch(open)
    UNTIL get_water_volume==0
    water_out_switch(close)
  6. halt(0)

3)根据你的实践,请分析“正常洗衣”与“快速洗衣”在用户目标和程序上的异同。 你认为是否存在改进(创新)空间,简单说明你的改进意见?
快速洗衣少了浸泡过程,其他一致,可以适当提高转动速度与力度。
4)通过步骤3),提取一些共性功能模块(函数),简化“正常洗衣”程序,使程序 变得更利于人类理解和修改维护。例如:
wait(time) //等待指定的时间;
注水(volume,timeout) //在指定时间内完成注水,否则停机;
排水(timeout)。 等子程序
FUNCTION wait(time)
SET nowTime=timecounter();
WHILE timecounter()-nowTime==time
ENDWHILE
ENDFUNCTION

FUNCTION 注水(volume,timeout)
SET nowTime=timecounter();
REPEAT
IF timecounter()-newTime==timeout THEN
halt(1)
ENDIF
water_in_switch(open)
UNTIL get_water_volume==volume
water_in_switch(close)
waterinswitch(close)
ENDFUNCTION

FUNCTION 排水(timeout)
SET nowTine=timecounter();
REPEAT
IF timecounter()-newTime==timeout THEN
halt(1)
ENDIF
water_out_switch(open)
UNTIL get_water_volume==0
water_out_switch(close)
ENDFUNCTION