新しく発言する  EXIT  インデックスへ
流れ図(フローチャート)を描く

  流れ図(フローチャート)を描く 山中和義 2008/01/09 16:18:14  (修正1回)
  つづき 山中和義 2008/01/09 16:20:23  (修正1回)

Re: 流れ図(フローチャート)を描く  返事を書く  ノートメニュー
山中和義 <drdlxujciw> 2008/01/09 16:20:23 ** この記事は1回修正されてます
つづき


PICTURE FChart(n,d$,s$,c$) !流れ図記号を描く
IF BLEN(s$)>9 THEN LET a=BLEN(s$)/9 ELSE LET a=1 !枠
DRAW chart(n) WITH SCALE(a,1) !※横倍のみ

SET TEXT JUSTIFY "CENTER","HALF"
PLOT TEXT ,AT 0,0: s$ !処理の内容

IF d$<>"" AND VAL(d$(1:1))=0 THEN !右方向に矢印がある場合、左側に記述する
SET TEXT JUSTIFY "RIGHT","HALF"
PLOT TEXT ,AT -a,0: c$
ELSE
SET TEXT JUSTIFY "LEFT","HALF"
PLOT TEXT ,AT a,0: c$ !枠外の注釈
END IF

IF d$<>"" THEN !矢印
LET d=VAL(d$(1:1)) !1文字目は向き、2文字目以降は注釈
DRAW ArrowAndComment(d,d$(2:LEN(d$)))
END IF
END PICTURE
PICTURE FChart2(n,d1$,d2$,s$,c$) !流れ図記号を描く
DRAW FChart(n,d1$,s$,c$)

IF n=5 THEN !「判断」なら、もう1本
LET d2=VAL(d2$(1:1))
DRAW ArrowAndComment(d2,d2$(2:LEN(d2$)))
ELSEIF n=6 OR n=7 OR n=16 OR n=17 THEN !「繰り返し」なら、番号を対応させる
SET TEXT JUSTIFY "CENTER","HALF"
PLOT TEXT ,AT 0,0.4: "ループ "&d2$(1:1)
END IF
END PICTURE
!--------------------

SUB ReadData(n,d1$,d2$,s$,c$) !流れ図記号を得る
READ n
IF n=5 OR n=6 OR n=7 OR n=16 OR n=17 THEN !「判断」「繰り返し」は矢印が2本!
READ d1$,d2$
ELSE
READ d1$
LET d2$=""
END IF
READ s$,c$
END SUB
!-------------------- ここまでがサブルーチン



LET h=7 !行数
LET w=5 !列数

LET s=MAX((w+1)*2,(h+1)*1.5)
SET WINDOW 0,s,0,s !表示領域 ※正方形
DRAW grid(2,1.5)

FOR x=1 TO w !格子を走査する
FOR y=h TO 1 STEP -1
CALL ReadData(n,d1$,d2$,s$,c$) !流れ図記号を得る

DRAW FChart2(n,d1$,d2$,s$,c$) WITH SHIFT(x*2,y*1.5) !流れ図を描く
NEXT y
NEXT x



!列挙する ※h*w個


!例題3 縦の長さが12、横の長さが34の長方形の面積を計算する
DATA 1,"3","開始",""
DATA 3,"3","12→A",""
DATA 3,"3","34→B",""
DATA 3,"3","A*B→S",""
DATA 9,"3","S",""
DATA 1,"","終了",""
DATA 0,"","",""


!例題4 商品の定価を入力して、税込み(5%)の値段を計算する
DATA 1,"3","開始",""
DATA 8,"3","A",""
DATA 3,"3","A*1.05→B",""
DATA 9,"3","B",""
DATA 1,"","終了",""
DATA 0,"","",""
DATA 0,"","",""


!例題6 1から10までの和を表示する
DATA 1,"3","開始",""
DATA 3,"3","0→W",""
DATA 16,"3","1","K=1,10,1",""
DATA 3,"3","W+K→W",""
DATA 17,"3","1","",""
DATA 9,"3","W",""
DATA 1,"","終了",""


!例題8 1つの数値xを入力して,その値が1ならば「正解です」,そうでないならば「エラー」と表示する
DATA 1,"3","開始",""
DATA 8,"3","X",""
DATA 5,"3=","0≠","X:1",""
DATA 9,"3","""正解です""",""
DATA 13,"3","├",""
DATA 1,"","終了",""
DATA 0,"","",""

DATA 0,"","",""
DATA 0,"","",""
DATA 13,"3","┐",""
DATA 9,"","""エラー""",""
DATA 13,"2","┘",""
DATA 0,"","",""
DATA 0,"","",""


END

   └流れ図でアルゴリズムを検証する。2008.1.1... 山中和義 2008/01/10 12:53:57  (修正4回)
    ├つづき 山中和義 2008/01/10 12:55:58  (修正4回)
    ├つづき2 山中和義 2008/01/10 13:01:14  (修正4回)
    ├つづき3 山中和義 2008/01/11 21:06:32  (修正2回)
    └つづき4 山中和義 2008/01/13 20:10:24  (修正1回)
     └サンプル(右から左へ受け流す〜♪) 山中和義 2008/01/13 20:18:23  (修正1回)
      └高校数学「数値計算とコンピュータ」 山中和義 2008/01/22 20:37:31  (修正1回)

 インデックスへ  EXIT
新規発言を反映させるにはブラウザの更新ボタンを押してください。