青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 60  文章 - 5  trackbacks - 0
<2011年10月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

常用鏈接

留言簿(2)

隨筆分類(42)

隨筆檔案(60)

文章檔案(2)

我收藏的博客

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

原文:http://www.cprogramming.com/tutorial/thinking.html
很多人通過Email問我,怎樣開始寫一個程序。也許最好的建議非常簡單,把程序的步驟寫下來:一旦你開始把想法或者代碼寫下來后,你就會對你的項目有一些感覺了。通常程序設計有兩種通用的做法:從上到下的方式和從下到上的方式。
A lot of people email me asking the way to start some program or another. Perhaps the best advice is simply to start writing down a layout for the program: once you start writing down ideas or code you'll start to get a feel for your project. There are two standard methods of program design: the top-down approach and the bottom-up approach. Top-down programming involves writing code that calls functions you haven't defined and working through the general algorithm before writing the functions that do the processing. Top-down programming is, to a good degree, a very abstract way of writing code because it starts out by using functions you haven't designed, and that you perhaps do not know how to design. The bottom-up approach to programming is the opposite: the programmer writes the basic functions she realizes will be necessary at some point in the programming and then work up to the more complex parts of the program.

比較有意思的是,那兩種方法都是關注程序中要執(zhí)行的動作或方法,而不是關注程序要處理的數(shù)據(jù)。很多時候,寫程序最好的方法是,寫出你將要用到或處理的數(shù)據(jù),然后再從上到下的想怎么樣去處理這些數(shù)據(jù),最后才能得到你需要的結果。首先定義數(shù)據(jù),然后再寫出那些要處理這些數(shù)據(jù)的相關的函數(shù)。,這樣你才會得到你的程序應該怎樣寫的基本思路,
It's interesting that both of these approaches focus on the actions of the program rather than the objects the program manipulates - variables. Many times, the best way to write a program is to figure out the variables you need to work with and then progress with a top-down approach to the program that manipulates those variables. By defining variables first and then working with functions that work on them, you will always maintain a basic foundation of what your program should be doing. Once you have an idea of what variables you will be using, then you can write functions to perform the operations you need to perform on the variables while maintaining sight of the goal. Finally you can write the code for each individual function.

Another value to defining variables before writing code is that many times you can accomplish an entire program without many functions; this fact is especially true when you are a beginner making simple programs. The variables give you the raw materials you need to begin working with the tools: loops, if statements, library functions, and perhaps user defined functions.


現(xiàn)在讓我們來看一個關于怎樣開始寫一個完整程序的例子。假設你要寫的程序是要模擬一個DVD商店的租售系統(tǒng),這個系統(tǒng)需要計算出出租DVD的總收入。你的程序有可能要求,需要輸入一個代碼,告訴你這個DVD租售的價格是2元一天還是是3元一天,然后還需要它出租了多少天,最后如果這個輸入的代碼是0,整個程序就結束了。你應該要分別計算出租金為3元/天和2元/天的DVD的出租的總天數(shù)。拿這個程序來說,思考設計程序的最好的方式是,想象為了計算出租金的收入,你需要存儲哪些信息:

 

  • 你需要一個變量用來存儲總收入,當程序結束時;
  • 你需要一個臨時變量用來存儲代表DVD的租金的代號;
  • 你需要一個臨時變量用來存儲某個DVD出租的天數(shù);
  • 你需要一個變量來存儲租金為3元/天的所有DVD出租了多少天的總數(shù);
  • 最后,你還需要一個變量來存儲租金為2元/天的所有DVD出租了多少天的總數(shù);

 

Let's take a look at an example of how to go about thinking about a program. If you were to write a program to simulate a video store rental system that calculates the gross revenue from rentals, you might be asked to write a program that accepts a code telling you whether a certain video was rented at $2.00 (input as 2) a day or $3.00 (input as 3) a day and then asks for how many days it was rented out for; finally, if the code for the cost of rental is 0 the program should terminate. You should also count the number of days videos were rented at $3.00 per day and $2.00 per day. The best way to think about the design for a program such as this one is to imagine what information you need to store in order to calculate the revenue:

  • you need a variable to store the total dollar amount at the end of the program;
  • you need a temporary variable to store the code for the cost of a transaction;
  • you need a temporary variable to store the number of days a specific video was rented;
  • you need a variable to store the number of days each video was rented;
  • you need a variable to count the total number of days $3.00 videos were rented;
  • finally, you need a variable to count the total number of days $2.00 videos were rented.

一旦你認識到你需要這些數(shù)據(jù),那么你就很容易想出如何處理這些數(shù)據(jù):比如,你知道租金2元/天的DVD的總收入=所有租金為2元/天DVD的出租天數(shù)之和*2;類似的也可以計算出租金3元/天的DVD的總收入。你也會理解這個“代表DVD的租金的代號”,這個變量的用處是,當用戶輸入某個DVD出租的天數(shù)時,決定哪個變量會被操作。在你的程序中你需要一個循環(huán)結構。


Once you realize you need these variables, you can easily imagine how to translate them in terms of each other: for example, you know the total amount of revenue is the number of days videos at $2.00 were rented times $2.00; in similar fashion, you know the relationship for $3.00 a day videos. You should understand that the transaction 'code' determines which variables are manipulated when the user inputs the number of days a specific video was rented (for example, whether to add to the count of days for $2.00 videos or $3.00 videos). You'll probably need a loop in your program (although you can't necessarily infer this from the variables).

 

程序的代碼有可能會像下面那樣:

The code might look as follows:

 1 
 3 int main()
 4 {
 5   int total_dollars = 0;
 6   int total_days_at_3_dollars = 0;
 7   int total_days_at_2_dollars = 0;
 8   int transaction_code = 0;
 9   int days_for_one_video = 0;
10   do
11   {
12     if(transaction_code==2)
13       total_days_at_2_dollars+=days_for_one_video;
14     if(transaction_code==3)
15       total_days_at_3_dollars+=days_for_one_video;
16     cout<<"Please enter a transaction code and number of days a video was rented: ";
17     cin>>transaction_code>>days_for_one_video;
18   }while(transaction_code!=0)
19   return 0
20 }

我希望,你現(xiàn)在已經有了一個基本的思路,在寫代碼之前,應該如何安排你的程序的結構。

Hopefully, you now have a basic idea of how to lay out your program structure in your mind before you begin to write code.

 

posted on 2011-10-19 11:00 黃劍父 閱讀(1908) 評論(0)  編輯 收藏 引用 所屬分類: 編程學院
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            在线视频成人| 欧美国产精品一区| 亚洲国产黄色| 久久综合影视| 免费黄网站欧美| 欧美成人一区在线| 亚洲精选一区二区| 午夜国产一区| 久久久xxx| 欧美日韩国产成人在线观看| 国产精品久久久久久久久免费 | 欧美日本国产视频| 欧美三级视频在线| 国产亚洲一区二区在线观看| 亚洲国产精品久久| 亚洲一区二区三区影院| 久久久www成人免费毛片麻豆| 欧美aa在线视频| 夜夜精品视频一区二区| 欧美亚洲免费电影| 欧美精品v日韩精品v国产精品| 国产精品入口夜色视频大尺度 | 久久久最新网址| 欧美日韩国产成人在线91| 国产日韩在线亚洲字幕中文| 亚洲人精品午夜| 欧美中在线观看| 91久久精品美女| 欧美一区二区视频在线| 欧美日韩精品免费观看视一区二区| 国产一区二区三区久久精品| 亚洲网址在线| 欧美激情一区在线观看| 亚洲女人天堂av| 欧美经典一区二区三区| 曰本成人黄色| 久久精品二区| 在线视频欧美一区| 欧美精品www在线观看| 黑人巨大精品欧美一区二区| 亚洲伊人久久综合| 亚洲精品一二| 欧美高清视频一区| 精品999成人| 久久久久久高潮国产精品视| 在线亚洲观看| 国产精品theporn| 亚洲午夜高清视频| 亚洲精品日韩激情在线电影| 欧美成va人片在线观看| 亚洲黄色毛片| 亚洲电影激情视频网站| 美女啪啪无遮挡免费久久网站| 国语自产精品视频在线看一大j8| 久久精品国产一区二区三区| 午夜视频久久久| 国产日韩欧美精品综合| 久久久91精品国产一区二区三区| 小处雏高清一区二区三区 | 99精品视频免费观看视频| 欧美精品一区二区在线观看| 亚洲高清精品中出| 欧美国产日韩一区二区三区| 免费日韩视频| 女仆av观看一区| 亚洲与欧洲av电影| 国产精品最新自拍| 欧美一区二区在线播放| 欧美一区免费视频| 激情欧美日韩| 亚洲成人直播| 欧美三级电影大全| 欧美亚洲一级| 欧美在线观看日本一区| 在线观看91精品国产麻豆| 欧美黄色影院| 欧美日韩高清区| 性欧美暴力猛交另类hd| 久久精品视频免费| 亚洲精品一区久久久久久| 亚洲乱码国产乱码精品精天堂| 国产精品v亚洲精品v日韩精品| 久久福利资源站| 蜜桃伊人久久| 午夜老司机精品| 久久频这里精品99香蕉| 亚洲四色影视在线观看| 欧美在线在线| 一区二区三区视频在线观看 | 男人插女人欧美| 欧美日韩精品欧美日韩精品| 欧美一级视频精品观看| 美女露胸一区二区三区| 午夜综合激情| 欧美chengren| 久久av免费一区| 欧美激情一区二区三级高清视频| 午夜久久福利| 欧美另类高清视频在线| 久久夜色撩人精品| 欧美午夜理伦三级在线观看| 女人天堂亚洲aⅴ在线观看| 国产精品国产一区二区| 欧美国产精品一区| 国产亚洲精品aa午夜观看| 亚洲免费成人av| 亚洲国产乱码最新视频| 亚洲欧美另类综合偷拍| 一区二区三区福利| 欧美成人午夜| 欧美成人蜜桃| 韩国福利一区| 午夜精品久久久久| 午夜视频一区二区| 欧美日韩伦理在线免费| 欧美成人免费在线观看| 韩国av一区二区三区| 亚洲一区二区三区四区五区黄 | 国产精品资源| 日韩一本二本av| 亚洲精品国精品久久99热| 久久婷婷av| 久久综合中文字幕| 国内自拍视频一区二区三区| 亚洲制服av| 在线视频你懂得一区| 亚洲一区二区在线视频| 你懂的成人av| 欧美a级在线| 亚洲第一级黄色片| 久久亚洲精选| 农村妇女精品| 在线欧美日韩精品| 麻豆成人在线观看| 欧美大尺度在线| 亚洲精品欧美日韩| 欧美精品 国产精品| 亚洲人在线视频| 中文久久乱码一区二区| 欧美视频在线免费看| 亚洲视频导航| 欧美一区二区成人| 国内外成人在线视频| 久久亚洲免费| 最新国产拍偷乱拍精品| 亚洲午夜激情免费视频| 国产精品成人一区二区艾草| 亚洲免费人成在线视频观看| 欧美专区亚洲专区| 伊大人香蕉综合8在线视| 欧美a级一区| 99视频超级精品| 欧美一级午夜免费电影| 国内揄拍国内精品少妇国语| 久久久久一区二区三区| 亚洲经典三级| 欧美在现视频| 亚洲国产视频一区二区| 欧美日韩精品综合| 亚洲欧美日本日韩| 欧美第一黄网免费网站| 一本综合久久| 国产亚洲毛片在线| 欧美高清视频免费观看| 在线中文字幕不卡| 久久久免费精品| 亚洲免费黄色| 国产婷婷一区二区| 欧美国产专区| 欧美在线首页| 亚洲另类在线视频| 另类酷文…触手系列精品集v1小说| 一本一道久久综合狠狠老精东影业| 国产伦精品一区二区三区在线观看| 久久久噜噜噜久久久| 在线亚洲高清视频| 亚洲高清在线精品| 欧美在线视频观看| 一区二区三区黄色| 狠狠色伊人亚洲综合网站色| 欧美日韩精品在线观看| 另类激情亚洲| 香蕉乱码成人久久天堂爱免费| 亚洲韩国日本中文字幕| 久久精品天堂| 亚洲欧美日韩国产综合| 亚洲精品少妇网址| 一区在线观看视频| 国产欧美一区二区精品性| 欧美精品一区二区三| 久久米奇亚洲| 欧美亚洲综合网| 中日韩午夜理伦电影免费| 亚洲国产精品久久91精品| 久久亚洲风情| 欧美一区二区精美| 亚洲一区在线视频| 亚洲欧美国内爽妇网| 亚洲视频在线观看网站| 亚洲一区国产精品|