【问题标题】:Drawing a Control Flow Graph with an output绘制带有输出的控制流图
【发布时间】:2018-05-31 22:55:09
【问题描述】:

我目前正在学习绘制控制流图,但我不确定是否适合以下场景:

对于以下代码片段,其中xy 是输入变量,z 是输出变量:

if x=0 then x:=10
if x<y-5 then y:=y-1 else x:=y+5
z:=y-x

这就是我所做的:

这是否正确?提前致谢。

【问题讨论】:

    标签: testing code-coverage control-flow-graph


    【解决方案1】:

    不,您的控制流程图不正确。节点代表基本代码块,这意味着它只能包含赋值语句,不能包含条件语句或循环。边表示条件,例如 if then else 语句和 case 语句。

    对于这个问题,

    1. Start node is the first node with an incoming arrow. So, remove the solid node at the top and leave the arrow as it is.
    2. Replace true in first left branch with x == 0
    3. Replace false in the first right branch with x != 0 and connect it to the node containing x < y-5. Remove the solid node.
    4. Replace true following node containing x < y-5 with x < y-5
    5. Replace false following node containing x < y-5 with x >= y-5
    6. Remove last two true on the edges
    7. Make the node containing z:=y-x as last node and remove the arrow and solid node after this node.
    

    【讨论】:

      猜你喜欢
      • 2012-10-18
      • 2022-08-23
      • 1970-01-01
      • 2011-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      相关资源
      最近更新 更多