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

隨筆 - 60  文章 - 5  trackbacks - 0
<2009年3月>
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

常用鏈接

留言簿(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>
            女生裸体视频一区二区三区| 久久久久99| 亚洲精品字幕| 久久婷婷丁香| 一区二区三区四区蜜桃| 久久久久国产精品麻豆ai换脸| 欧美精品激情在线观看| 国内精品一区二区三区| 午夜性色一区二区三区免费视频| 亚洲国产欧美一区| 亚洲一区二区免费| 欧美三级在线| 亚洲视频在线一区观看| 最新亚洲电影| 老鸭窝亚洲一区二区三区| 国产一区二区精品久久99| 在线成人性视频| 久热国产精品| 欧美在线观看一区二区| 国产精品一区二区女厕厕| 午夜精品久久久久| 亚洲综合色激情五月| 国产精品播放| 午夜视频在线观看一区二区| 亚洲午夜一区| 国产日韩欧美一区二区三区在线观看| 亚洲视频在线观看视频| 在线午夜精品自拍| 国产精品永久免费| 久久久久久夜| 久久蜜桃精品| 欧美aⅴ一区二区三区视频| 亚洲国产一区二区视频| 欧美激情中文字幕在线| 欧美女人交a| 亚洲色诱最新| 亚洲影视在线播放| 国产午夜精品美女视频明星a级| 久久不射中文字幕| 久久精品麻豆| 亚洲破处大片| 99re6这里只有精品| 国产精品卡一卡二| 久久精品综合网| 另类av一区二区| 一区二区三区黄色| 午夜精品久久久久久久白皮肤 | 国产精品网站在线观看| 久久成人精品电影| 久久青草福利网站| 久久激情综合网| 久久精品国产亚洲精品| 亚洲国产99| 99在线热播精品免费99热| 国产精品羞羞答答xxdd| 欧美一区二区在线观看| 亚洲人在线视频| 久久久91精品国产一区二区三区 | 亚洲品质自拍| 欧美手机在线| 久久久欧美精品| 欧美精品v国产精品v日韩精品 | 欧美第一黄网免费网站| 欧美日韩人人澡狠狠躁视频| 欧美综合国产| 欧美精品成人一区二区在线观看| 亚洲欧美日韩区| 久久久久www| 午夜精品久久久久久久蜜桃app| 久久久免费观看视频| 亚洲一区二区三区欧美 | 欧美精品三级| 久久精品一区四区| 欧美日韩综合网| 蜜臀av一级做a爰片久久| 91久久久亚洲精品| 久久久久久综合网天天| 亚洲精品免费一区二区三区| 久久久不卡网国产精品一区| 久久亚洲综合色| 国模精品一区二区三区| 国产精品资源| 亚洲精品裸体| 老司机久久99久久精品播放免费| 亚洲福利一区| 久热这里只精品99re8久| 91久久在线| 亚洲私人影院在线观看| 一区二区三区免费看| 欧美jizzhd精品欧美巨大免费| 国内一区二区三区| 欧美日韩国产在线播放网站| 另类av一区二区| 美女主播视频一区| 久久精品人人爽| 欧美三区视频| 亚洲国产欧美在线人成| 亚洲国产99| 在线成人av| 精品va天堂亚洲国产| 国产乱肥老妇国产一区二| 欧美理论电影在线观看| 欧美日韩一区二区在线播放| 国内精品免费午夜毛片| 欧美午夜在线一二页| 亚洲激情女人| 久久精品人人做人人爽| 欧美日韩综合视频网址| 欧美丰满高潮xxxx喷水动漫| 国内视频精品| 亚洲欧美美女| 亚洲欧美日韩精品一区二区| 欧美日韩成人免费| 一区二区激情视频| 欧美三级日本三级少妇99| 亚洲二区在线视频| 日韩香蕉视频| 久久综合一区| 欧美国产一区二区三区激情无套| 国内在线观看一区二区三区| 久久青青草综合| 麻豆精品精华液| 伊人久久亚洲热| 久久视频免费观看| 快播亚洲色图| 亚洲日本va午夜在线电影| 久久综合成人精品亚洲另类欧美| 久久久欧美一区二区| 国语对白精品一区二区| 久久大香伊蕉在人线观看热2| 久久精品国产视频| 亚洲国产欧美一区二区三区同亚洲 | 国产欧美一区二区三区另类精品| 西瓜成人精品人成网站| 欧美在线欧美在线| 亚洲激情第一页| 欧美精品日韩精品| 欧美专区中文字幕| 欧美国产在线观看| 性欧美精品高清| 国产一区二区三区日韩| 欧美经典一区二区| 亚洲一区中文字幕在线观看| 欧美黄在线观看| 免费成年人欧美视频| 亚洲美女视频网| 欧美高清视频在线播放| 一区二区日本视频| 欧美在线观看天堂一区二区三区| 18成人免费观看视频| 欧美国产视频在线观看| 午夜精品一区二区三区电影天堂| 久久久久久久网| 亚洲女人小视频在线观看| 国产亚洲毛片在线| 欧美视频一区二区三区…| 香蕉久久夜色精品国产| av成人免费观看| 另类激情亚洲| 久久精品欧洲| 中文国产成人精品| 国产精品黄页免费高清在线观看| 久久久久久久高潮| 一区二区三区日韩精品| 麻豆精品在线视频| 久久xxxx精品视频| 一区二区三区高清在线| 国语自产精品视频在线看一大j8 | 亚洲国产精品99久久久久久久久| 夜夜嗨一区二区| 国产亚洲欧美激情| 欧美精品大片| 久久精品国产一区二区三| 欧美激情a∨在线视频播放| 久久精品一区二区三区中文字幕| 日韩午夜免费视频| 国内精品国产成人| 国产精品www.| 欧美大成色www永久网站婷| 午夜欧美不卡精品aaaaa| 亚洲激情视频| 欧美亚洲免费电影| 欧美亚洲一区二区在线| av成人免费在线观看| 在线观看欧美成人| 国产麻豆午夜三级精品| 久久精彩免费视频| 久久久蜜桃精品| 久久精品国产亚洲a| 亚洲欧美日韩爽爽影院| 999亚洲国产精| 久久国产精品高清| 久久午夜av| 欧美在线黄色| 亚洲欧美另类国产| 中国成人亚色综合网站| 国产综合亚洲精品一区二| …久久精品99久久香蕉国产| 国产亚洲欧美aaaa| 国产欧美一区二区精品婷婷|