200 likes | 535 Views
BPC.1 Basic Programming Concepts. 1.1 Program development procedures 1.2 Problem analysis techniques 1.3 Algorithm design 1.4 Program debugging 1.5 Program documentation 1.6 Problem solving approaches 1.7 Structured programming 1.8 Good programming style.
E N D
BPC.1 Basic Programming Concepts 1.1 Program development procedures 1.2 Problem analysis techniques 1.3 Algorithm design 1.4 Program debugging 1.5 Program documentation 1.6 Problem solving approaches 1.7 Structured programming 1.8 Good programming style
Problem Analysis • Concept of modularity • Divide the statements into logical groups called module. • Each module performs one or two tasks. • The modules are usually written in the form of sub-programs. • Stepwise refinement • Break down a problem into smaller parts (or modules) until it becomes manageable.
Designing an algorithm • Algorithm • a set of ordered steps • Pseudocode is used to shorten the statement • There is NO syntax in writing algorithm • Pseudocode may include basic programming: 1. Using assignment statement e.g. A5, A = 5 or A := 5 means putting 5 into variable A 2. Using conditional statements, like • If...then...else...end if, represent different actions some conditions. 3. Using indentation to clarify the statements blocks.
Using program flowchart to realise algorithm • Program flowchart • Graphical representation of instructions • Representing the logic of a single program • Can be converted into programming constructs: • branching • iteration structures
E.g. 1 • Example 1 Assign different value to Y depending on the input value.
E.g. 2 • Example 2 Calculate the sum of 1 + 2 + ... + 10. • Output is 55
Debugging and Testing • Debugging • Finding out errors (bugs錯誤[蟲]) and • Removing them • Compare the output with the expected one • Testing • Verify that the program will process all data properly • Should use both • valid and invalid test data
Programming Errors • 1. Syntax (語法) Errors • Violation of the grammatical rule of a programming language • e.g. Wrong spelling of some keywords • 2. Run-time (執行) Errors • Cause a program to terminate abnormally • e.g. Division-by-zero error, Out of memory error. • 3. Logical (邏輯) Errors • Caused by an incorrect algorithm • Producing an unexpected result, e.g. an average mark > 100 • May not be discovered until it is too late • So, programs should be well tested before use
Documentation • Documentation • Written description about the solution to a problem • User manual • Instruct user how to operate the program effectively • Including: 1. Procedures in starting the program 2. Description of buttons/commands in the menu 3. Description of error messages and how to handle such errors 4. Description of defaults values 5. Sample procedures in finishing a task
Documentation • Technical documentation • for programmers or technical people • providing information about how the solution is developed • Useful for maintenance and further development • Including: 1. Description of the problem 2. Algorithm 3. Program flowchart 4. Program listing with comments 5. List of files used 6. Test data 7. Sample output
Different Ways to Solve a Problem • A. Packaged software vs Custom software • Packaged software • Pre-written software available for purchase • Less expensive • Company may need to adjust in order to use packaged software • Custom software • Written by IT department • Match the company’s requirements • But, more expensive and take a longer time to develop
Different Ways to Solve a Problem • B. Planning vs Without Planning • Usually more than one logical solution • An easy one may solve the problem temporarily • But, when new problem arises, programs may be difficult to change • Programs should have careful planning before development • Otherwise, take much longer and more effort to change
Structured programming • Sequence • Steps follow each other in a logical sequence. • Alternation • They may be if or case statements. • Iteration • They are while, for or repeat statements.
Good programming style • Structured program • Modular design • Readable • Reusable • Reliable • Portable • Program documentation