Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Program Planning and Design Important stages before actual program is written.

Similar presentations


Presentation on theme: "1 Program Planning and Design Important stages before actual program is written."— Presentation transcript:

1 1 Program Planning and Design Important stages before actual program is written

2 2 Steps to Problem-solving Analyze the problem and develop specifications Analyze the problem and develop specifications Design solutions Design solutions Code the program with documentation Code the program with documentation Test the program Test the program Validate the program Validate the program

3 3 Algorithm Definition 1: The sequence of steps required to solve a problem Definition 1: The sequence of steps required to solve a problem Definition 2: A definite list of well-defined instructions for completing a task; that given an initial state, will proceed through a well-defined series of successive states, eventually terminating in an end-state. Definition 2: A definite list of well-defined instructions for completing a task; that given an initial state, will proceed through a well-defined series of successive states, eventually terminating in an end-state.

4 4 Presentation of Algorithms Structure Chart: Structure Chart: Structure of modules needed to solve a problem. Structure of modules needed to solve a problem. Pseudo-codes: Pseudo-codes: Semiformal, English-like list of steps of the algorithm. Semiformal, English-like list of steps of the algorithm. Flow-charts: Flow-charts: Graphical/schematic representation of an algorithm. Graphical/schematic representation of an algorithm.

5 5 Structure Chart To chart out the modules and statements to break down a programming problem To chart out the modules and statements to break down a programming problem Multiply two integers Get two integers Formula Print result no1no2 Multiply= no1 * no2 Multiply

6 6 Pseudo-code Semi-formal, English-like description of logic of the algorithm Semi-formal, English-like description of logic of the algorithm Helps programmer to “think out” the program Helps programmer to “think out” the program Advantage: Advantage: Simple Simple Easy to understand Easy to understand

7 7 Example of Pseudo-code: To calculate Sales Amount: 1. First get user to enter quantity 2. Get the price of the product 3. Calculate amount = price * quantity 4. Display the amount

8 8 Example of Pseudo-code: Write an algorithm of a program that will accept four marks and determine a student’s final grade and indicate whether it is passing or failing. The passing mark is 50. The final grade is calculated as the average of four marks. Write an algorithm of a program that will accept four marks and determine a student’s final grade and indicate whether it is passing or failing. The passing mark is 50. The final grade is calculated as the average of four marks. Pseudo-code: Input a set of 4 marks Input a set of 4 marks Calculate their average by summing and dividing by 4 Calculate their average by summing and dividing by 4 If average is below 50 If average is below 50 Print “FAIL” else Print “PASS”

9 9 Flow-Charts Graphical representation of an algorithm Graphical representation of an algorithm Uses symbols and shapes to describe flow or process of the algorithm to solve a problem. Uses symbols and shapes to describe flow or process of the algorithm to solve a problem. Example: Example:

10 10 Flow-charting Symbols Selection/ Decisions ProcessConnectors Input/Output Terminators Direction of Flow Loop

11 11 Flow-charting Symbols (continued)

12 12 Example of Flowchart: START Input M1, M2, M3, M4 GRADE  (M1+M2+M3+M4)/4 IS GRADE<5 0 STOP YESNO Print PASSPrint FAIL Pseudo-code: Input a set of 4 marks Input a set of 4 marks Calculate their average by summing and dividing by 4 Calculate their average by summing and dividing by 4 If average is below 50 If average is below 50 Print “FAIL” else Print “PASS”

13 13 Example of Flowchart (continued) :

14 14 Debugging A process to remove error A process to remove error Error = bug, the first computer “bug” is a bug found on a printer Error = bug, the first computer “bug” is a bug found on a printer 4 kinds of errors : 4 kinds of errors : Syntax error Syntax error Run-time error Run-time error Undetected error Undetected error Logic/semantic error Logic/semantic error

15 15 1. Syntax error Violation of the C grammar rules, detected during program translation (compilation) Violation of the C grammar rules, detected during program translation (compilation) Example: Example: Missing semicolon Missing semicolon Undeclared variable Undeclared variable

16 16 2. Run-Time Errors An attempt to perform an invalid operation detected during program execution An attempt to perform an invalid operation detected during program execution Example: Example: Dividing a number by zero Dividing a number by zero When a run time occurs, the computer will stop executing your program and will display a diagnostic message that indicates the line where an error was detected When a run time occurs, the computer will stop executing your program and will display a diagnostic message that indicates the line where an error was detected

17 17 3. Undetected errors Many execution error may not prevent a C programming from running to completion but they may simply lead to incorrect result Many execution error may not prevent a C programming from running to completion but they may simply lead to incorrect result Example: Example: When programmer forgot to write ‘&’ in scanf When programmer forgot to write ‘&’ in scanf The program runs to completion using whatever “garbage” value originally in the memory locations named to variable in scanf The program runs to completion using whatever “garbage” value originally in the memory locations named to variable in scanf

18 18 4. Logic Errors An error caused by following an incorrect algorithm An error caused by following an incorrect algorithm Usually do not cause run-time errors and do not display error messages, they are difficult to detect Usually do not cause run-time errors and do not display error messages, they are difficult to detect


Download ppt "1 Program Planning and Design Important stages before actual program is written."

Similar presentations


Ads by Google