当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

香港科技大学:《软件开发》教学资源(PPT课件讲稿)Functions

资源类别:文库,文档格式:PPT,文档页数:65,文件大小:497KB,团购合买
点击下载完整版文档(PPT)

Functions

Functions

Slide 2 Where are we now? now Midterm: structured programming Simple types of variables Array 3 program structures Functions(subprograms) cin(>)/cout(<< (File lO)

Slide 2 Where are we now? Simple types of variables 3 program structures cin(>>)/cout(<<) Array Functions (subprograms) (File I/O) Midterm: structured programming now

Slide 3 Review Problem Solving process le Define and analyze the problem What is the input output? What constraints must be satisfied? 0Eo What information is essential? Design an algorithm What steps must be done? Wirte down the solution steps in detail o05 Implement a program -programming or coding Compile, test, and debug the program -testing Document and maintain the program

Slide 3 Review: Problem Solving Process Define and analyze the problem What is the input & output? What constraints must be satisfied? What information is essential? Design an algorithm What steps must be done? Wirte down the solution steps in detail Implement a program - programming or coding. Compile, test, and debug the program - testing. Document and maintain the program

Slide 4 Top-down analysis A complex problem is often easier to solve by dividing it into several smaller parts ( subproblems), each of which can be solved by itself This is called top-down programming Let's take the example of Diamand drawing

Slide 4 Top-down analysis A complex problem is often easier to solve by dividing it into several smaller parts (subproblems), each of which can be solved by itself. This is called top-down programming. Let’s take the example of Diamand drawing!

Slide 5 Example: Diamond Pattern Input: nothing Output: print out a diamond pattern 大大大 大大大大大 大大大大大大大 大大大大大大大 大大大大大

Slide 5 Example: Diamond Pattern Input: nothing Output: print out a diamond pattern * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Slide 6 Example: top-down analysis Output: print out a diamond pattern print out the upper half > upper triangular form print out the lower half lower triangular form

Slide 6 Example: top-down analysis Output: print out a diamond pattern print out the upper half → upper triangular form print out the lower half → lower triangular form

Slide 7 Example: upper triangular pattern Upper triangular pattern row 1: print 4 spaces, 1 star; row 2: print 3 spaces, 3 stars, row 3: print 2 spaces, 5 stars row 4: print 1 space, 7 stars; ******** row 5: print 0 spaces, 9 stars

Slide 7 Example: upper triangular pattern Upper triangular pattern: row 1: print 4 spaces, 1 star; row 2: print 3 spaces, 3 stars; row 3: print 2 spaces, 5 stars; row 4: print 1 space, 7 stars; row 5: print 0 spaces, 9 stars; * * * * * * * * * * * * * * * * * * * * * * * * *

Slide 8 Example: top-down refinement Refinement = row 1: print (5-row) spaces, (2*row-1)stars row 2: print (5-row) spaces, (2*row-1)stars row 3: print (5-row) spaces, (2*row-1)stars, 大大大大大 row 4: print (5-row) spaces, (2* row-1)stars row 5: print (5-row) spaces, (2*row-1)stars, For each row(more exactly from row 1 to 5), always do Print 5-row spaces Print 2 *row-1 stars int rowi It's a loop: pseudo-code while (row<=5)t print 5-row spaces; p

Slide 8 Example: top-down refinement Refinement: row 1: print (5-row) spaces, (2*row - 1) stars; row 2: print (5-row) spaces, (2*row - 1) stars; row 3: print (5-row) spaces, (2*row - 1) stars; row 4: print (5-row) spaces, (2*row - 1) stars; row 5: print (5-row) spaces, (2*row - 1) stars; For each ‘row’ (more exactly from row 1 to 5), always do Print 5-row spaces Print 2*row-1 stars It’s a loop: pseudo-code * * * * * * * * * * * * * * * * * * * * * * * * * int row; row=1; while(row<=5){ print 5-row spaces; print 2*row-1 stars; row=row+1; }

Slide 9 Example: algorithm int row, space, stari int row i row=l; row=1 while(row=5)i while(row<=5) space=li while(space<=5-row)( 5-row spaces cout < 2*row-1 starsi space=space+li row=row+l; star= while(star<=2*row-1) cout < l* star=star+1 cout < endl row=row+1

Slide 9 Example: algorithm int row, space, star; row=1; while(row<=5){ space=1; while(space<=5-row) { cout << " "; space=space+1; } star=1; while(star<=2*row-1) { cout << "*"; star=star+1; } cout << endl ; row=row+1; } int row; row=1; while(row<=5){ 5-row spaces; 2*row-1 stars; row=row+1; }

Slide 10 Introduction to functions The subproblems are solved by subprograms, called functions in C++ main( is the first function, then executes these functions so that the original problem is solved

Slide 10 Introduction to Functions The subproblems are solved by subprograms, called functions in C++. main() is the first function, then executes these functions so that the original problem is solved

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共65页,可试读20页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有