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

隨筆 - 60  文章 - 5  trackbacks - 0
<2009年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用鏈接

留言簿(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.

比較有意思的是,那兩種方法都是關注程序中要執行的動作或方法,而不是關注程序要處理的數據。很多時候,寫程序最好的方法是,寫出你將要用到或處理的數據,然后再從上到下的想怎么樣去處理這些數據,最后才能得到你需要的結果。首先定義數據,然后再寫出那些要處理這些數據的相關的函數。,這樣你才會得到你的程序應該怎樣寫的基本思路,
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.


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

 

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

 

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.

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


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 }

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

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 黃劍父 閱讀(1917) 評論(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>
            99riav国产精品| 亚洲男女毛片无遮挡| 欧美a级片网站| 亚洲国产精品ⅴa在线观看| 欧美成人日韩| 欧美日韩国产系列| 午夜在线一区| 久久精品久久99精品久久| 一区二区在线看| 亚洲精品美女91| 欧美午夜欧美| 久久久久.com| 欧美精品精品一区| 亚洲欧美影院| 久久色在线播放| 一区二区免费在线视频| 午夜亚洲伦理| 亚洲精品一区二区在线观看| 日韩视频一区二区三区在线播放免费观看| 欧美三级电影一区| 久久这里只有精品视频首页| 免费在线成人av| 欧美与黑人午夜性猛交久久久| 欧美一区二区三区日韩视频| 亚洲国产精品久久久| 99精品欧美| 一区二区亚洲精品| 亚洲网站在线播放| 亚洲人精品午夜| 欧美一级欧美一级在线播放| 99热免费精品| 久久综合给合| 亚洲欧美日韩国产另类专区| 免费观看日韩av| 欧美一区二区三区久久精品茉莉花| 久久午夜激情| 久久国产免费看| 欧美日韩免费一区二区三区| 美女黄毛**国产精品啪啪| 国产精品h在线观看| 欧美xxx在线观看| 国产一区二区三区四区hd| 亚洲精品老司机| 亚洲黄色一区二区三区| 午夜国产精品影院在线观看| 99人久久精品视频最新地址| 老司机成人网| 久久久亚洲午夜电影| 国产精品视频xxx| 99国产精品国产精品毛片| 亚洲人成绝费网站色www| 欧美亚洲在线| 久久精品国产99| 国产精品乱看| 亚洲一区二区三区欧美 | 久久亚洲不卡| 久久www免费人成看片高清 | 欧美一区二区三区四区在线观看| 99精品欧美一区二区三区| 久久一区二区三区av| 久久久久国色av免费看影院| 国产精品久久久久影院亚瑟| 中文久久精品| 亚洲欧美在线x视频| 国产精品少妇自拍| 亚洲一区二区三区四区视频| 亚洲永久在线| 国产精品一区久久久久| 亚洲一区二区在线免费观看| 亚洲欧美日韩天堂| 国产精品永久在线| 羞羞色国产精品| 久久婷婷一区| 亚洲国产精品一区在线观看不卡 | 99亚洲一区二区| 亚洲一二三区精品| 国产精品久久国产精品99gif| 一区二区三区欧美日韩| 亚洲欧美另类国产| 国产午夜精品在线观看| 久久久久国产一区二区三区四区 | 久久久久se| 在线观看一区视频| 欧美大片免费久久精品三p| 亚洲高清视频中文字幕| 一区二区激情| 国产伦一区二区三区色一情| 久久久久高清| 亚洲精品久久7777| 午夜精品一区二区在线观看| 国产亚洲欧美日韩日本| 老司机午夜免费精品视频| 亚洲精品美女| 久久久久久夜精品精品免费| 亚洲高清在线观看| 国产精品久久久久77777| 久久九九免费| 99re6热只有精品免费观看| 羞羞答答国产精品www一本| 亚洲高清中文字幕| 国产精品久久久久久久久久久久久| 欧美一区二区三区成人 | 午夜精品久久一牛影视| 在线日韩一区二区| 欧美性做爰毛片| 另类图片综合电影| 亚洲亚洲精品三区日韩精品在线视频 | 久久久国产一区二区| 99re66热这里只有精品3直播 | 久久激情综合| 99re6这里只有精品| 国产亚洲精品一区二区| 欧美岛国激情| 久久久国产视频91| 亚洲欧美日韩精品| 夜夜嗨av一区二区三区四区| 久久资源在线| 欧美有码在线观看视频| 中文网丁香综合网| 亚洲国产精品成人综合色在线婷婷| 国产精品欧美在线| 欧美日韩大片| 欧美成人精品福利| 久久福利电影| 午夜精品国产精品大乳美女| 亚洲精品日韩欧美| 亚洲国产精品久久久久秋霞蜜臀| 久久国产精品72免费观看| 亚洲视频狠狠| 一区二区三区你懂的| 最新精品在线| 亚洲国产精品www| 激情一区二区| 在线播放精品| 精品成人国产| 国内精品久久久久久| 国产亚洲福利社区一区| 国产欧美91| 国产一区二区精品丝袜| 国产日韩欧美一区在线| 国产精品久久久久久久7电影| 欧美日韩亚洲免费| 欧美日韩精品一二三区| 欧美精品九九99久久| 欧美精品激情在线| 欧美色一级片| 欧美涩涩视频| 国产伦理一区| 国语自产精品视频在线看8查询8| 国产精品一区二区在线| 国产精品影视天天线| 国产欧美精品国产国产专区| 国产一区二区日韩精品欧美精品 | 欧美国产先锋| 欧美日韩一区二区视频在线观看 | 国产欧美91| 国产一区二区主播在线| 韩日精品视频| 亚洲毛片av| 亚洲欧美日韩在线不卡| 欧美在线免费观看| 久久午夜电影网| 亚洲国产乱码最新视频| 亚洲精品美女久久7777777| 一区二区三区精品国产| 先锋影音久久| 欧美xart系列在线观看| 欧美日韩在线另类| 国产日韩一区在线| 亚洲黄色天堂| 亚洲欧美偷拍卡通变态| 久久久久久网| 亚洲人午夜精品| 亚洲欧美在线高清| 免费视频一区二区三区在线观看| 欧美日韩精品免费看| 国产日韩亚洲| 日韩视频中文字幕| 久久精品官网| 亚洲日本黄色| 久久久久久久国产| 欧美少妇一区二区| 尤物精品国产第一福利三区 | 国产欧美日韩一级| 亚洲精品美女久久久久| 小黄鸭视频精品导航| 欧美国产日本高清在线| 亚洲调教视频在线观看| 欧美xxxx在线观看| 国产一区二区精品久久| 亚洲小少妇裸体bbw| 女主播福利一区| 午夜精品久久| 欧美视频二区| 亚洲欧洲在线观看| 久久婷婷一区| 亚洲欧洲av一区二区| 欧美三区视频| 一本大道久久a久久综合婷婷 | 一本色道久久综合一区|