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

隨筆 - 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 黃劍父 閱讀(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>
            中日韩高清电影网| 99在线精品观看| 亚洲激情一区二区| 在线不卡亚洲| 激情成人av| 伊人久久婷婷| 亚洲精品久久久久| 亚洲午夜激情网页| 午夜久久久久久久久久一区二区| 国产精品99久久久久久白浆小说| 亚洲一区二区在线看| 欧美在线黄色| 亚洲第一区在线| 欧美成人首页| 日韩小视频在线观看专区| 一本久道久久综合婷婷鲸鱼| 99精品久久| 性做久久久久久免费观看欧美| 久久精品国产在热久久 | 久久精品国产v日韩v亚洲| 欧美在线播放高清精品| 久久一二三四| 亚洲国产黄色| 亚洲欧美在线免费观看| 蜜臀av在线播放一区二区三区| 欧美风情在线观看| 国产精品久久久久久久第一福利| 国产精品一二三四| 亚洲韩国一区二区三区| 午夜视频一区| 亚洲国产mv| 亚洲综合成人在线| 欧美日韩成人综合| 国产精品手机在线| 久久国产乱子精品免费女 | 久久精品国产99精品国产亚洲性色 | 99成人免费视频| 午夜天堂精品久久久久| 免费看亚洲片| 亚洲欧美激情诱惑| 欧美激情1区| 国产亚洲欧美激情| 亚洲视频久久| 欧美成人免费在线| 欧美在线观看www| 欧美日韩国产系列| ●精品国产综合乱码久久久久| 午夜精品亚洲| 夜夜嗨av一区二区三区网页| 久久亚洲高清| 国产精品一卡二| 一本色道久久综合亚洲91| 久久国产日韩欧美| 亚洲片国产一区一级在线观看| 欧美在线视频免费| 欧美丝袜一区二区| 一本色道久久88综合亚洲精品ⅰ | 麻豆av一区二区三区| 国产精品成人一区二区三区夜夜夜| 国外成人在线视频| 亚洲欧美另类在线| 日韩视频免费观看高清在线视频| 可以免费看不卡的av网站| 国产伦精品一区二区三区高清 | 欧美怡红院视频一区二区三区| 亚洲大胆美女视频| 欧美一级淫片播放口| 国产精品美女久久久| 一本不卡影院| 亚洲日韩中文字幕在线播放| 久久综合激情| 在线免费观看成人网| 久久婷婷久久| 久久久精品国产一区二区三区| 国产性做久久久久久| 午夜精品福利视频| 亚洲永久免费观看| 午夜一区二区三区在线观看| 国产精品久久二区| 亚洲一区在线视频| 一本色道久久综合亚洲精品不 | 亚洲精品美女在线| 亚洲福利一区| 欧美屁股在线| 亚洲综合国产| 午夜精品视频一区| 一区二区三区无毛| 欧美肥婆在线| 欧美高清视频| 性刺激综合网| 久久国产精品第一页| 1024欧美极品| 日韩视频精品在线| 国产一区二区三区久久久久久久久| 久久久精品五月天| 欧美成年人视频| 亚洲一区二区欧美日韩| 午夜久久久久久久久久一区二区| 国内久久精品视频| 亚洲电影免费在线| 国产精品对白刺激久久久| 久久riav二区三区| 欧美美女bb生活片| 久久激情视频免费观看| 久久字幕精品一区| 亚洲午夜影视影院在线观看| 性一交一乱一区二区洋洋av| 亚洲黄色小视频| 亚洲天堂偷拍| 亚洲国产婷婷| 午夜久久久久久| 夜夜爽av福利精品导航 | 欧美日韩国产一级片| 欧美一区二区三区精品| 久久久国产精品亚洲一区| 亚洲免费激情| 免费成人性网站| 午夜精品久久久久99热蜜桃导演| 欧美与欧洲交xxxx免费观看| 在线中文字幕一区| 麻豆freexxxx性91精品| 亚洲一区国产精品| 久久免费高清视频| 性欧美1819性猛交| 欧美国产一区在线| 免费高清在线视频一区·| 欧美色视频一区| 欧美顶级艳妇交换群宴| 国内精品视频久久| 欧美影院视频| 亚洲综合精品| 欧美日韩精品免费观看| 暖暖成人免费视频| 国产人成一区二区三区影院| 亚洲精品午夜| 亚洲毛片一区| 久久久午夜视频| 亚洲电影免费在线| 欧美一区二区三区免费视| 亚洲性夜色噜噜噜7777| 欧美成人精品高清在线播放| 久久综合狠狠综合久久综合88| 欧美午夜不卡在线观看免费 | 亚洲视频一区二区免费在线观看| 欧美一级片一区| 羞羞色国产精品| 国产精品青草久久| 亚洲最新在线| 一区二区三区蜜桃网| 欧美激情亚洲另类| 欧美成人综合一区| 亚洲国产精品欧美一二99| 久久久亚洲欧洲日产国码αv| 久久成人一区| 国产综合色精品一区二区三区| 亚洲自拍偷拍视频| 亚洲欧美日韩一区二区三区在线观看| 欧美精品亚洲精品| 亚洲美女电影在线| 欧美一区1区三区3区公司| 国产乱码精品| 欧美一区二区三区在线免费观看| 香蕉视频成人在线观看| 国产精品国产三级国产普通话三级 | 亚洲国产成人在线播放| 久久久久久久一区| 美女视频黄a大片欧美| 在线观看日产精品| 欧美成人久久| 日韩午夜视频在线观看| 亚洲在线一区二区| 国产欧美日韩视频一区二区| 久久九九热re6这里有精品 | 中国女人久久久| 久久精品综合一区| 亚洲国产精品一区二区三区| 六月天综合网| aa级大片欧美三级| 久久精品91久久久久久再现| 精品99视频| 欧美日一区二区三区在线观看国产免 | 在线看无码的免费网站| 欧美成人免费va影院高清| 99热在这里有精品免费| 欧美在线高清| 亚洲片在线资源| 国产精品区一区| 欧美护士18xxxxhd| 午夜精品久久久久久久久久久久久 | 久久大香伊蕉在人线观看热2| 亚洲网站在线| 免费视频一区| 亚洲一区观看| 亚洲日本一区二区| 国产乱码精品一区二区三区不卡| 老司机一区二区三区| 亚洲午夜av电影| 亚洲高清av在线| 久久精品国亚洲| 亚洲色在线视频|