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

隨筆 - 60  文章 - 5  trackbacks - 0
<2011年4月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用鏈接

留言簿(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 黃劍父 閱讀(1913) 評論(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>
            亚洲综合成人在线| 国产美女精品免费电影| 久久久国产一区二区| 蜜桃av一区| 欧美日韩情趣电影| 国产一区深夜福利| 亚洲一区二区三区视频| 老司机精品福利视频| 制服丝袜亚洲播放| 亚洲国产视频一区| 中文在线资源观看网站视频免费不卡 | 久久av资源网| 亚洲品质自拍| 久久精品视频在线| 国产无遮挡一区二区三区毛片日本| 亚洲免费观看高清在线观看 | 欧美在线视频在线播放完整版免费观看| 欧美激情一区二区三区四区| 亚洲毛片在线看| 蜜臀av国产精品久久久久| 国产一区久久久| 久久综合久久综合这里只有精品| 国产精品稀缺呦系列在线| 日韩视频欧美视频| 99av国产精品欲麻豆| 欧美日韩成人在线观看| 亚洲一区二区免费在线| 亚洲人体影院| 欧美日韩国产在线播放网站| 亚洲精品永久免费| 国产精品xvideos88| 国内外成人免费激情在线视频 | 99国内精品久久| 日韩一级片网址| 欧美日韩成人| 国产精品美女久久久久久2018 | 欧美精品一区二区三区在线看午夜 | 中文国产成人精品| 麻豆av一区二区三区| 亚欧成人精品| 国产综合在线视频| 国产婷婷精品| 99精品视频免费| aa级大片欧美三级| 国产精品永久免费观看| 久久久国产一区二区| 久久九九国产| 欧美一区二区三区视频免费| 狠狠综合久久av一区二区小说| 亚洲午夜高清视频| 欧美一区二区高清在线观看| 激情六月婷婷久久| 91久久精品国产91久久性色| 午夜亚洲激情| 国产欧美日韩精品一区| 免费一区二区三区| 欧美日韩久久不卡| 久久高清免费观看| 免费看的黄色欧美网站| 欧美日韩高清在线观看| 久久成人人人人精品欧| 亚洲制服欧美中文字幕中文字幕| 国产欧美成人| 妖精成人www高清在线观看| **欧美日韩vr在线| 一区二区三区视频观看| 亚洲精品国产系列| 欧美日韩调教| 久久久综合免费视频| 亚洲欧美www| 亚洲国产99精品国自产| 一本大道久久a久久综合婷婷| 国内精品视频在线观看| 亚洲精品国精品久久99热| 久久久久久日产精品| 久久久亚洲一区| 国产精品亚发布| 亚洲三级免费电影| 日韩一级不卡| 欧美激情综合在线| 99精品国产在热久久婷婷| 美日韩精品视频| 久久综合色播五月| 99视频精品免费观看| 国产日韩精品一区二区三区在线| 久久亚洲综合网| 久久综合九色九九| 久久免费视频这里只有精品| 久久精品理论片| 久久精品中文字幕一区| 亚洲自拍偷拍视频| 久久av老司机精品网站导航| 亚洲视频网在线直播| 久久夜色精品国产亚洲aⅴ| 亚洲欧美日韩综合| 欧美精品尤物在线| 亚洲精品日本| 亚洲人成网站在线观看播放| 亚洲国产精品一区制服丝袜 | 麻豆久久精品| 亚洲国产综合视频在线观看| 日韩写真视频在线观看| 母乳一区在线观看| 久热精品视频在线免费观看 | 国产一区二区中文字幕免费看| 亚洲午夜女主播在线直播| 亚洲精品乱码久久久久久按摩观| 久久久亚洲一区| 久久午夜激情| 欧美日本一区| 99精品福利视频| 一本色道久久综合亚洲精品婷婷| 欧美成黄导航| 亚洲国产精品激情在线观看| 在线看片成人| 久久久久免费观看| 蜜桃av噜噜一区| 91久久久精品| 欧美韩日高清| 亚洲理伦在线| 亚洲在线一区二区三区| 欧美日韩视频一区二区三区| 免费高清在线视频一区·| 国产精品女人网站| 亚洲免费一级电影| 亚洲最新视频在线播放| 欧美午夜理伦三级在线观看| 另类综合日韩欧美亚洲| 久久精品人人| 欧美成人亚洲成人| 日韩视频在线一区| 欧美日韩理论| 亚洲一区二区在线免费观看视频| 亚洲青色在线| 久久久久国产免费免费| 欧美电影免费观看网站| 亚洲片国产一区一级在线观看| 麻豆freexxxx性91精品| 亚洲精品一区在线观看香蕉| 亚洲一级片在线看| 国产亚洲高清视频| 日韩天堂av| 久久精品国产99国产精品澳门| 国产一区二区三区四区| 久久婷婷人人澡人人喊人人爽| 亚洲国产综合在线| 欧美一区三区三区高中清蜜桃 | 亚洲观看高清完整版在线观看| 欧美精品一区二区三| 亚洲一区二区三区中文字幕| 亚洲欧美卡通另类91av| 欧美午夜精品久久久久久久| 亚洲国产精品日韩| 亚洲综合第一| 亚洲青色在线| 欧美区在线播放| 国产精品欧美久久久久无广告| 亚洲精品永久免费| 麻豆91精品| 欧美a级一区二区| 在线不卡视频| 久久久无码精品亚洲日韩按摩| 欧美在线观看视频一区二区三区 | 欧美一区午夜精品| 国内精品伊人久久久久av影院| 亚洲综合色视频| 免播放器亚洲| 亚洲精选一区| 国产视频在线观看一区二区| 欧美一区二区在线看| 亚洲国产精品久久久久婷婷老年| 亚洲国产一区视频| 欧美一区成人| 亚洲精品一区二区三| 午夜精品久久久久久99热| 亚洲第一级黄色片| 欧美日本亚洲韩国国产| 久久久久久有精品国产| 欧美激情1区| 欧美影院久久久| 亚洲电影在线观看| 国产精品九九久久久久久久| 欧美一区永久视频免费观看| 欧美性事免费在线观看| 美女免费视频一区| 亚洲电影下载| 久久九九免费| 91久久久在线| 国产欧美韩日| 欧美激情视频在线免费观看 欧美视频免费一| 日韩一级精品视频在线观看| 狂野欧美激情性xxxx欧美| 亚洲小说区图片区| 伊人婷婷久久| 国产精品久久久久三级| 麻豆91精品91久久久的内涵| 亚洲黄色av一区| 欧美日韩精品久久久| 久久久精品五月天| 亚洲毛片在线观看|