next up previous contents
Next: vi 編輯器 Up: C 語言簡介 Previous: 高階與低階   Contents

程式撰寫步驟

  1. 程式規劃:在撰寫程式前先規劃是非常重要的。
    1. 流程圖符號:

      \begin{tikzpicture}[node distance=1.5cm]\setlength \baselineskip{1ex}
\node [terminator] (st) {Start/End};
\node [decision, below of=st] (pfile) {Decision};
\node [block, below of=pfile] (readp) {Process};
\node [data, below of=readp] (inout) {Intput/Output};
\end{tikzpicture}

    2. 畫流程圖

      \begin{tikzpicture}[node distance=1.5cm]\setlength \baselineskip{1ex}
\node [terminator] (st) {Start};
\node [decision, below of=st] (pfile) {file?};
\node [block, below of=pfile] (readp) {ReadParameters};
\node [block, below of=readp] (indate) {Date};
\node [decision, below of=indate] (legal) {Legal?};
\path [line] ;
%\node [block, below of=para_exist] (read) {Read};
\node [data, left of=legal,node distance=4cm] (waring) {Waring};
\node [block, below of=legal] (cweek) {getWeek};
\node [block, below of=cweek] (mpaper) {makePaper};
\node [block, right of=cweek,node distance=4cm] (allpaper) {makePaper};
\node [decision, below of=allpaper] (wknu) {wknu $>18$\ ?};
% \node [data, right of=readpara,node distance=4cm] (para) {Parameters};
\node [terminator, below of=mpaper] (stop) {Stop};
\par
\path [line] (st) -- (pfile);
\path [line] (pfile) -- node[right]{yes}(readp);
\path [line] (pfile) -\vert node[below right]{No}(waring);
\path [line] (waring) \vert- (stop);
\path [line] (readp) -- (indate);
\path [line] (indate) -- (legal);
\path [line] (legal) -\vert node[below left]{all or All}(allpaper);
\path [line] (legal) -- node[right]{yes}(cweek);
\path [line] (cweek) -- (mpaper);
\path [line] (mpaper) -- (stop);
\path [line] (allpaper) -- (wknu);
\path [line] (wknu) \vert- node[above left]{yes}(stop);
%\path [line] (legal.west) -\vert node[below right] {other} ($(legal.west) + (-2.13,-1.5)$) \vert- (stop.west);
\path [line] (legal.west) -- node[below]{other}(waring.east);
\path [line] (wknu.east) -\vert node[above left] {no} ($(wknu.east) + (0.5,1.5)$) \vert- (allpaper.east);
\end{tikzpicture}

  2. 撰寫程式碼
    1. 依照流程一步一步寫。
    2. 撰寫時儘可能加入註解。
  3. 編譯與連結。
  4. 執行程式。
  5. 除錯與測試。
  6. 程式碼修飾與儲存。


2015-01-16