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

隨筆 - 60  文章 - 5  trackbacks - 0
<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用鏈接

留言簿(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 黃劍父 閱讀(1922) 評論(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成人国产| 亚洲欧美www| 亚洲精品女人| 欧美一区二区日韩| 国产精品久久久久久久久久妞妞 | 亚洲高清一区二区三区| 一区二区三区国产精华| 亚洲成色最大综合在线| 久久亚洲高清| 亚洲福利精品| 欧美成人一区二区三区在线观看| 久久精品国产亚洲aⅴ| 国产精品豆花视频| 亚洲综合视频在线| 亚洲一区在线播放| 国产麻豆91精品| 久久久久.com| 久久中文字幕导航| 国产专区欧美精品| 美腿丝袜亚洲色图| 欧美成人第一页| 伊人男人综合视频网| 欧美大色视频| 欧美视频第二页| 欧美在线观看视频一区二区三区| 午夜亚洲福利| 曰本成人黄色| 亚洲人成人一区二区在线观看| 欧美日韩一区二| 亚洲国产精彩中文乱码av在线播放| 国产女主播在线一区二区| 亚洲一区二区三区中文字幕在线| 亚洲色图在线视频| 国产日韩欧美在线观看| 麻豆国产精品777777在线| 欧美1区视频| 亚洲高清电影| 亚洲欧洲日本一区二区三区| 欧美午夜免费| 欧美国产精品一区| 国产一区二区三区久久精品| 亚洲免费成人av| 亚洲高清视频一区| 欧美一级视频精品观看| 亚洲午夜精品视频| 欧美成年人视频网站欧美| 久久精品国产免费看久久精品| 中文亚洲欧美| 国产欧美日韩另类视频免费观看| 亚洲高清一区二| 黄页网站一区| 亚洲综合999| 亚洲免费视频在线观看| 欧美成人小视频| 欧美成人午夜视频| 激情欧美一区| 久久国产视频网站| 久久精品国产精品亚洲| 国产精品亚洲а∨天堂免在线| 一本色道婷婷久久欧美| 99天天综合性| 欧美激情一区二区三区| 亚洲激情在线观看| 亚洲精品国产精品国自产观看浪潮| 久久精品国产欧美激情| 久热综合在线亚洲精品| 国产亚洲一区在线播放| 欧美一区二区久久久| 久久精品国产v日韩v亚洲| 国产日产欧产精品推荐色| 午夜激情综合网| 久久久久久久91| 激情久久一区| 嫩草成人www欧美| 亚洲大黄网站| 中文在线一区| 国产精品国产三级国产普通话三级| 一本色道久久综合狠狠躁篇怎么玩| 亚洲无线一线二线三线区别av| 欧美日韩午夜| 午夜免费日韩视频| 久久成人在线| 亚洲大胆在线| 欧美精品一区二区久久婷婷| 日韩视频在线观看国产| 亚洲欧美日韩一区二区三区在线| 国产精品丝袜白浆摸在线| 亚洲欧美视频一区| 麻豆精品在线播放| 一区二区冒白浆视频| 国产精品剧情在线亚洲| 久久久久久久性| 亚洲精品国产精品久久清纯直播| 亚洲无亚洲人成网站77777| 国产欧美日韩精品丝袜高跟鞋| 久久久久久黄| 一本色道久久综合精品竹菊| 久久精品在线观看| 亚洲美女在线看| 国产欧美在线观看一区| 麻豆91精品91久久久的内涵| 一本色道久久综合一区| 久久亚洲精品一区二区| 夜夜爽av福利精品导航| 国产一区二区三区直播精品电影| 免费一区二区三区| 亚洲免费在线精品一区| 亚洲国产精品综合| 久久久国产精品一区二区三区| 亚洲精品欧美日韩专区| 国产午夜精品在线| 欧美日韩一区二区免费在线观看| 欧美在线一级视频| 亚洲免费高清视频| 嫩草伊人久久精品少妇av杨幂| 亚洲香蕉在线观看| 亚洲成人资源网| 国产日韩高清一区二区三区在线| 欧美成人激情在线| 久久国产免费| 亚洲在线1234| 99精品福利视频| 亚洲国产精品国自产拍av秋霞 | 欧美69视频| 午夜欧美大片免费观看| 亚洲老板91色精品久久| 久久久久久久成人| 亚洲免费视频一区二区| 亚洲精选视频免费看| 在线电影欧美日韩一区二区私密| 国产精品视频在线观看| 欧美日韩视频不卡| 欧美成人精品在线视频| 久久久国际精品| 欧美一级视频精品观看| 亚洲欧美成人精品| 中国成人黄色视屏| 一本一本久久a久久精品综合麻豆| 亚洲国产精品成人综合| 欧美va日韩va| 欧美国产另类| 欧美成人精品一区| 欧美国产精品va在线观看| 你懂的视频一区二区| 猛干欧美女孩| 欧美国产日韩在线| 亚洲国产午夜| 亚洲精品国产欧美| 一本久久综合亚洲鲁鲁| 一区二区三区国产盗摄| 亚洲婷婷在线| 午夜精品短视频| 久久国产精品网站| 久久久精品一品道一区| 久久在线免费| 欧美区一区二| 国产精品免费观看视频| 国产精品日韩在线| 国产在线欧美| 亚洲国产一二三| 一区二区毛片| 亚洲欧美高清| 久久美女艺术照精彩视频福利播放| 六月天综合网| 亚洲人被黑人高潮完整版| 在线视频亚洲| 欧美一区视频| 毛片av中文字幕一区二区| 欧美日韩综合视频| 国产一区日韩欧美| 亚洲国产精品999| 亚洲一级二级在线| 久久男女视频| 亚洲国产另类精品专区| 亚洲色图综合久久| 久久综合久久综合久久| 欧美三级韩国三级日本三斤| 国产一区二区三区四区五区美女 | 国产精品久久久久久影视 | 国产欧美一区二区三区国产幕精品| 国产一区二区三区的电影| 亚洲日本免费| 久久精品国产99国产精品| 欧美激情第五页| 亚洲一区三区在线观看| 美女视频网站黄色亚洲| 国产精品欧美久久| 亚洲激情中文1区| 欧美一区二区三区在线播放| 亚洲国产cao| 欧美一区亚洲| 国产精品福利久久久| 亚洲大片av| 久久精品99无色码中文字幕| 亚洲欧洲精品天堂一级| 久久精品国产99精品国产亚洲性色| 欧美日韩情趣电影| 亚洲国产福利在线| 久久久女女女女999久久|