自頂向下,逐步求精

基本思想
從欲求解的原問題出發,運用科學抽象的方法,把它分解成若干相對獨立的小問題,依次細化,直至各個小問題獲得解決爲止。

求精技術
如圖
這裏寫圖片描述
求精技術包含: 順序連接的求精、分支和選擇的求精、循環的求精、遞歸的求精

實例
洗衣機:

將問題分解爲:1.接通電源,打開洗衣機,放入衣物 2.選擇水量,洗衣模式 3.打開水龍頭,接入水源 4.開始洗滌 5.洗滌完畢,提示斷開電源

僞代碼:
plug in //接通電源
open the washer //打開洗衣機
choose how much water // 選擇水量
put in clothes // 放入衣物

/*
洗滌
*/

begin choose mode // 選擇模式

if choose 快速洗
  then turn on the switch //接入水源
    input water //注水
    turn off the switch//停止注水
    start //開始
    while(time <= 5min)
     do wash //洗滌
    end
     output//排水

if choose 標準洗
  then turn on the switch //接入水源
    input water //注水
    turn off the switch//停止注水
    start //開始
    while(time <= 10min)
     do wash //洗滌
    end
     output//排水

if choose 強力洗
  then turn on the switch //接入水源
    input water //注水
    turn off the switch//停止注水
    start //開始
    while(time <= 15min)
     do wash //洗滌
    end
     output//排水

end

/*
脫水
*/

while(time <= 5min)
 do 滾筒旋轉,脫水
end

/*
結束
*/

ring//提示
turn off//關閉

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章