




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、程式設(shè)計(jì)簡(jiǎn)介李俊宏2006/11/03程式設(shè)計(jì)簡(jiǎn)介李俊宏何謂程式與程式設(shè)計(jì)程式控制電腦如何做動(dòng)作的指令集合程式設(shè)計(jì)設(shè)計(jì)一組指令集合控制電腦做動(dòng)作何謂程式與程式設(shè)計(jì)程式控制電腦如何做動(dòng)作的指令集合程式設(shè)計(jì)設(shè)何謂電腦系統(tǒng)以及為何要作程式設(shè)計(jì)作業(yè)系統(tǒng)使用者使用者使用者程式設(shè)計(jì)師程式編譯軟體組合語言編譯軟體文字編輯軟體資料庫系統(tǒng)軟體電腦硬體電腦軟體Office 軟體黃易群俠傳遊戲軟體系統(tǒng)軟體何謂電腦系統(tǒng)以及為何要作程式設(shè)計(jì)作業(yè)系統(tǒng)使用者使用者使用者程由硬體觀點(diǎn)看程式設(shè)計(jì)計(jì)算邏輯單元控制單元暫存器主記憶體輸入輸出硬碟控制器外接硬體界面CPU電腦程式由硬體觀點(diǎn)看程式設(shè)計(jì)計(jì)算邏輯單元控制單元暫存器主記憶體輸
2、入輸程式語言, 程式, c+之間的關(guān)係為何程式控制電腦如何做動(dòng)作的指令集合程式語言寫指令集合時(shí)須符合的格式C+ 語言一種程式語言程式語言, 程式, c+之間的關(guān)係為何程式控制電腦如何做動(dòng)機(jī)器語言, 組合語言, 與高階語言三種程式語言(依與硬體相關(guān)性分類)機(jī)器語言 控制機(jī)器的特定數(shù)字字串-人類很難看懂例子:+1300042774+1400593419+1200274027組合語言比較像文字的控制機(jī)器的指令須組譯器轉(zhuǎn)成機(jī)器可以看懂的機(jī)器語言例子:LOAD BASEPAYADD OVERPAYSTORE GROSSPAY高階語言更像文字(英文)的控制機(jī)器的指令用數(shù)學(xué)符號(hào)來表示運(yùn)算式例子grossPa
3、y = basePay + overTimePay1/* Fig. 2.1: fig02_01.c2 A first program in C */3#include 45int main()67 printf( Welcome to C!n );89 return 0;10 機(jī)器語言, 組合語言, 與高階語言三種程式語言(依與硬體相關(guān)基礎(chǔ)的程式發(fā)展環(huán)境基礎(chǔ)的程式發(fā)展步驟編輯前置處理編譯連結(jié)載入執(zhí)行 編輯程式處理程式的前置碼載入主記憶體CPU按順序一個(gè)一個(gè)執(zhí)行被轉(zhuǎn)成機(jī)器語言的程式碼編譯程式轉(zhuǎn)成機(jī)器語言並存到儲(chǔ)存裝置連結(jié)外部的函式庫(別人寫好的)載入器主記憶體編譯器編輯器前置處理器連結(jié)器主記憶體
4、.DiskDisk磁碟CPUDiskDiskIDE(整合開發(fā)環(huán)境)基礎(chǔ)的程式發(fā)展環(huán)境基礎(chǔ)的程式發(fā)展步驟編輯程式處理程式的前程式的整體觀點(diǎn)電腦系統(tǒng)使用者其他系統(tǒng)ControlInterfaceData硬體觀點(diǎn)輸出入裝置CPU儲(chǔ)存裝置視窗畫面程式執(zhí)行的控制資料結(jié)構(gòu)軟體觀點(diǎn)程式的整體觀點(diǎn)電腦系統(tǒng)使用者其他系統(tǒng)ControlInter程式例子1/* Fig. 2.1: fig02_01.c2 A first program in C+ */3#include 44using std:cout;5int main()67 cout“我是李俊宏”;89 return 0;10 程式例子1/* Fig. 2
5、.1: fig02_01.c三大程式基本要素#include int main() int row = 10, column; while ( row = 1 ) column = 1; while ( column = 10 ) printf( %s, row % 2 ? ); +column; -row; printf( n ); return 0;資料控制流程動(dòng)作三大程式基本要素#include 資料控制資料: Variable (變 數(shù))#include main() int a, b;a = 1;b = a + 2;printf(The value of 1+2 is %i., b)
6、;031ab? ? ? ? ? ? ?0000 0000 0000 00010000 0000 0000 0011The value of 1+2 is 3.電腦記憶體 RAM資料: Variable (變 數(shù))#include = 60 ) printf( Passedn ); truefalsegrade = 60print “Passed”The if Selection StructurePseuThe if/else Selection StructureC code:if ( grade = 60 ) printf( Passedn);else printf( Failedn);
7、truefalseprint “Failed”print “Passed”grade = 60The if/else Selection StructurThe while Repetition StructureExample: int product = 2;while ( product = 1000 )product = 2 * product;product = 1000product = 2 * producttruefalseThe while Repetition StructureThe for Repetition Structure格式for (初值; 狀況測(cè)試; 增加
8、) 要重覆的內(nèi)容 Example: for( int counter = 1; counter = 10; counter+ ) printf( %dn, counter );印出整數(shù) 1 - 10No semicolon (;) after last expressioncounter=10printf( %dn, counter )truefalseint counter=1The for Repetition Structure格式The switch Multiple-Selection Structure格式switch ( value )case 1:動(dòng)作break;case 2:
9、動(dòng)作break;default:動(dòng)作break;break; 離開的點(diǎn)The switch Multiple-Selection switch 多重選擇結(jié)構(gòu)Flowchart of the switch structuretruefalse.case acase a action(s)breakcase bcase b action(s)breakfalsefalsecase zcase z action(s)breaktruetruedefault action(s)switch 多重選擇結(jié)構(gòu)Flowchart of the do/while 重覆結(jié)構(gòu)Example (counter = 1
10、):do printf( %d , counter ); while (+counter = 10);Prints the integers from 1 to 10truefalse動(dòng)作(s)條件do/while 重覆結(jié)構(gòu)Example (counter 動(dòng)作功能函數(shù)結(jié)構(gòu)化程式設(shè)計(jì)動(dòng)作功能函數(shù)結(jié)構(gòu)化程式設(shè)計(jì)介紹.Rule 2Rule 2Rule 2規(guī)則 1 由最簡(jiǎn)單的流程圖開始規(guī)則 2 任意一個(gè)程序方塊可以被分解成二個(gè)連續(xù)的小程序方塊結(jié)構(gòu)化程式設(shè)計(jì)介紹.Rule 2Rule 2Rule 2規(guī)則結(jié)構(gòu)化程式設(shè)計(jì)介紹Rule 3Rule 3Rule 3規(guī)則 3 將任意一個(gè)程序方塊用控制結(jié)構(gòu)來取代結(jié)
11、構(gòu)化程式設(shè)計(jì)介紹Rule 3Rule 3Rule 3規(guī)則 結(jié)構(gòu)化程式設(shè)計(jì)的目標(biāo)分解並各個(gè)擊破 由小程序方塊或元件開始建構(gòu)一個(gè)程式這些小程序方塊叫作程式模組程式模組比單一的程式更好管理結(jié)構(gòu)化程式設(shè)計(jì)的目標(biāo)分解並各個(gè)擊破 在 C 語言中的程式模組FunctionsModules in CPrograms combine user-defined functions with library functionsC standard library has a wide variety of functionsFunction callsInvoking functionsProvide functi
12、on name and arguments (data)Function performs operations or manipulationsFunction returns resultsFunction call analogy:Boss asks worker to complete taskWorker gets information, does task, returns resultInformation hiding: boss does not know details在 C 語言中的程式模組FunctionsMath Library FunctionsMath libr
13、ary functions perform common mathematical calculations#include Format for calling functionsFunctionName( argument );If multiple arguments, use comma-separated listprintf( %.2f, sqrt( 900.0 ) ); Calls function sqrt, which returns the square root of its argumentAll math functions return data type doub
14、leArguments may be constants, variables, or expressionsSome math library function examplesfabs(x) absolute value of x fabs(-5.0) is 5.0pow(x, y) power pow(2,7) is 128refer to p.146 fig. 5.2 .More informationMath Library FunctionsMath lib1/* Fig. 5.4: fig05_04.c2 Finding the maximum of three integers
15、 */3#include 45int maximum( int, int, int ); /* function prototype */67int main()89 int a, b, c;1011 printf( Enter three integers: );12 scanf( %d%d%d, &a, &b, &c );13 printf( Maximum is: %dn, maximum( a, b, c ) );1415 return 0;161718/* Function maximum definition */19int maximum( int x, int y, int z
16、 )2021 int max = x;2223 if ( y max )24 max = y;2526 if ( z max )27 max = z;2829 return max;30Function prototype(3 parameters)2. Input values2.1 Call functionFunction definition1/* Fig. 5.4: fig05_04.c2 FunctionsFunctionsModularize a programAll variables declared inside functions are local variablesK
17、nown only in function definedParametersCommunicate information between functionsLocal variablesBenefits of functionsDivide and conquerManageable program developmentSoftware reusabilityUse existing functions as building blocks for new programsAbstraction - hide internal details (library functions)Avo
18、id code repetitionFunctionsFunctionsFunction DefinitionsFunction definition format (continued)return-value-type function-name( parameter-list ) declarations and statements Declarations and statements: function body (block)Variables can be declared inside blocks (can be nested)Functions can not be defined inside other functionsReturning controlIf nothing returned return; or, until reaches right braceIf something returned return expression;Function DefinitionsFunction dFunction PrototypesFunction prototype Function nameParameters
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年法律風(fēng)險(xiǎn)與合規(guī)管理考試試題及答案
- CL汽車公司存貨內(nèi)部控制案例分析
- 高級(jí)語言考試試題及答案
- 青海大學(xué)考試試題及答案
- 語文招生考試試題及答案
- 2025年中國濕用磁粉市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國杏鮑菇市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國開門提示器市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國家用空調(diào)空氣過濾器市場(chǎng)調(diào)查研究報(bào)告
- 培訓(xùn)綜合服務(wù)協(xié)議書范本
- 統(tǒng)編版語文六年級(jí)下冊(cè)第一單元“民風(fēng)民俗”作業(yè)設(shè)計(jì)
- 改革開放與新時(shí)代知到智慧樹章節(jié)測(cè)試課后答案2024年秋同濟(jì)大學(xué)
- 雙全日培訓(xùn)課件
- 甲油膠行業(yè)報(bào)告
- 醫(yī)務(wù)人員職業(yè)暴露與防護(hù)講課
- 山東省萊西市2024-2025學(xué)年高一語文下學(xué)期3月月考試題含解析
- 康復(fù)科人員崗位考核制度(3篇)
- 實(shí)驗(yàn)動(dòng)物生物樣本質(zhì)量控制規(guī)范
- 智能機(jī)器人配送行業(yè)現(xiàn)狀分析及未來三至五年行業(yè)發(fā)展報(bào)告
- 炎癥性腸病的外科治療
- 復(fù)變函數(shù)與積分變換課程教案講義
評(píng)論
0/150
提交評(píng)論