Chapter 3 Part 1:Top-down Program Design Part 2:Relational and Logical Operators @日济大学 TONGJI UNIVERSITY
Chapter 3 Part 1: Top-down Program Design Part 2: Relational and Logical Operators
Top-down Program Design(1/14) Top-down and bottom-up design Top-down and bottom-up are both strategies o,mostly involving software. Top-down design is the process of starting with a large task and breaking it down into smaller,more easily understandable pieces(subtasks),which perform a portion of the desired task. Bottom-up design is the piecing together of systems to give rise to grander systems,thus making the original systems sub-systems of the emergent system. @月停大学 TONGJI UNIVERSITY
➢ Top-down and bottom-up design Top-down and bottom-up are both strategies o, mostly involving software. ✓ Top-down design is the process of starting with a large task and breaking it down into smaller, more easily understandable pieces(subtasks), which perform a portion of the desired task. ✓ Bottom-up design is the piecing together of systems to give rise to grander systems, thus making the original systems sub-systems of the emergent system. Top-down Program Design(1/14)
Top-down Program Design(2/14) >The top-down design progress Clearly state the problem that you are trying to solve. Define the inputs required by the program and the outputs to be produced by the program. Design the algorithm that you intend to implement in the program. Turn the algorithm into MATLAB statement. Test the resulting MATLAB program. @日济大学 AW TONGJI UNIVERSITY
➢ The top-down design progress ✓ Clearly state the problem that you are trying to solve. ✓ Define the inputs required by the program and the outputs to be produced by the program. ✓ Design the algorithm that you intend to implement in the program. ✓ Turn the algorithm into MATLAB statement. ✓ Test the resulting MATLAB program. Top-down Program Design(2/14)
Top-down Program Design(3/14) Start State the problem If the subtasks are large,the designer can break Define inputs them up into even smaller sub-subtasks and outputs Decomposition Design the algorithm Stepwise refinement Convert algorithm into MATLAB Define the funcions of the piece in statements greater and greater detail CDHAW Test the End resulting program @月两大学 TONGJI UNIVERSITY
Start State the problem Define inputs and outputs Design the algorithm Convert algorithm into MATLAB statements Test the resulting program End Decomposition Stepwise refinement If the subtasks are large, the designer can break them up into even smaller sub-subtasks Define the funcions of the piece in greater and greater detail Top-down Program Design(3/14)
Top-down Program Design(4/14) Pseudocode >As a part of the design process,it is necessary to describe the algorithm that you intend to implement. >The description of the algorithm should be in a standard form that is easy for both you and other people to understand, and it should aid you in turning your concept into MATLAB code. Pseudocode @日济大学 TONGJI UNIVERSITY
➢ As a part of the design process, it is necessary to describe the algorithm that you intend to implement. ➢ The description of the algorithm should be in a standard form that is easy for both you and other people to understand, and it should aid you in turning your concept into MATLAB code. Pseudocode Top-down Program Design(4/14) Pseudocode
Top-down Program Design(5/14) Pseudocode >A hybrid mixture of MATLAB and English for defining algorithms. >Independent of any programming language so it can be easily converted to any programming language Example pseudocode: Prompt user to enter temperature in degrees Fahrenheit Read temperature in degrees Fahrenheit (temp f) temp_k (in Kelvins)<(5/9)*(temp_f-32)+273.15 Write temperature in degree Kelvins @月停大学 TONGJI UNIVERSITY
➢ A hybrid mixture of MATLAB and English for defining algorithms. ➢ Independent of any programming language so it can be easily converted to any programming language ➢ Example pseudocode: Prompt user to enter temperature in degrees Fahrenheit Read temperature in degrees Fahrenheit (temp_f) temp_k (in Kelvins) (5/9) * (temp_f – 32) + 273.15 Write temperature in degree Kelvins Top-down Program Design(5/14) Pseudocode
Top-down Program Design(6/14) Testing In a large programming project,the time actually spent programming is surprisingly small. In the book The Mythical Man-Month,Frederick P.Brooks,ir suggests that in a typical large software project: 1/6 of the time is spent writing the program 1/3 of the time is spent planning what to do 1/2 of the time is spent testing @日济大学 AW TONGJI UNIVERSITY
➢ In a large programming project, the time actually spent programming is surprisingly small. ➢ In the book The Mythical Man-Month,Frederick P.Brooks,jr suggests that in a typical large software project: ✓ 1/6 of the time is spent writing the program ✓ 1/3 of the time is spent planning what to do ✓ 1/2 of the time is spent testing Top-down Program Design(6/14) Testing
Top-down Program Design(7/14) Testing >A typical testing process for large program Test individual subtasks:unit testing Add tested components one by one and test them together: build √Alpha release Beta release n√Finished program @凡两大学 AW TONGJI UNIVERSITY
➢ A typical testing process for large program ✓ Test individual subtasks: unit testing ✓ Add tested components one by one and test them together: build ✓ Alpha release ✓ Beta release ✓ Finished program Top-down Program Design(7/14) Testing
Top-down Program Design(8/14) Testing When we have written a program and it is not working, how do we debugging? >Three types of errors are found in MATLAB programs. √Syntax error Caused by the spelling errors or punctuation errors. >x=(y+3)/2) ?x=(y+3)/2) Error:Unbalanced or misused parentheses or brackets. Solution:Check spelling and punctuation 同濟大学 AW TONGJI UNIVERSITY
When we have written a program and it is not working, how do we debugging? ➢ Three types of errors are found in MATLAB programs. ✓ Syntax error Caused by the spelling errors or punctuation errors. Solution: Check spelling and punctuation Top-down Program Design(8/14) Testing
Top-down Program Design(9/14) Testing √Run-time error It occurs when an illegal mathematical operation is attempted during program execution.(For example attempting to divide by 0) >>x=pi/log(1) Warning:Divide by zero. X= Inf Solution: 2 ·Check input data Can remove“,”or add“disp'statements @月停大学 AW TONGJI UNIVERSITY
✓ Run-time error It occurs when an illegal mathematical operation is attempted during program execution. (For example , attempting to divide by 0) Solution: • Check input data • Can remove “;” or add “disp” statements Top-down Program Design(9/14) Testing