bpc.1 basic programming concepts

16
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

Upload: sanjiv

Post on 10-Jan-2016

31 views

Category:

Documents


0 download

DESCRIPTION

BPC.1 Basic Programming Concepts. 1.1 Program development procedures 1.2 Problem analysis techniques 1.3 Algorithm design 1.4Program debugging 1.5Program documentation 1.6Problem solving approaches 1.7Structured programming 1.8Good programming style. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: BPC.1  Basic Programming Concepts

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

Page 2: BPC.1  Basic Programming Concepts

Program development procedures

Step 1 Problem definition

It is to find out what the problem is.

Consult the client to know exactly what kind of

house is needed. Write down the requests.

Step 2 Problem Analysis

It is to find out what data are available and what

kind of output is required.

Look into the requests. Determine the resources

needed to fulfil the requests.

Step 3 Algorithm design

It is to design a set of steps (an algortithm) to

solve the problem. The algorithm can be represent

in the form of pseudo- code, program flowchart

etc.

Design the house with sketch diagrams. Instruct

the workers about the schedule and steps in

constructing the house.

Page 3: BPC.1  Basic Programming Concepts

Program development procedures

Step 4 Program codiing

The steps in the algorithm are written down in a

programming language.

Build the house.

Step 5 Program debugging and testing

The program is tested and corrected to make sure

that it gives the desired result.

Inspect the house and test the structure and other

facilities.

Step 6 Program documentation

Program documentation is simply a detailed

description of the program.

Provide a detail diagram about the house to the

client.

Page 4: BPC.1  Basic Programming Concepts

Problem Analysis

Concept of modularityDivide 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.

Page 5: BPC.1  Basic Programming Concepts

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 A2. Using conditional statements, like If...then...else...end if, represent different actions some

conditions.3. Using indentation to clarify the statements blocks.

Page 6: BPC.1  Basic Programming Concepts

Using program flowchart to realise algorithm

Program flowchart Graphical representation of instructionsRepresenting the logic of a single

programCan be converted into programming

constructs: branching iteration structures

Page 7: BPC.1  Basic Programming Concepts

E.g. 1

Example 1 Assign different value to Y depending on the input value.

10 INPUT X

20 IF X <= 0 THEN

30 Y -1040 ELSE

50 Y 660 END IF

Page 8: BPC.1  Basic Programming Concepts

E.g. 2

Example 2 Calculate the sum of 1 + 2 + ... + 10.

Output is 55

10 S 0

20 X 0

30 X X + 1

40 S S + X

50 IF X < 10 THEN

60 GOTO 30

70 END IF

80 OUTPUT S

Page 9: BPC.1  Basic Programming Concepts

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

Page 10: BPC.1  Basic Programming Concepts

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

Page 11: BPC.1  Basic Programming Concepts

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 menu3. Description of error messages and how to handle such errors4. Description of defaults values5. Sample procedures in finishing a task

Page 12: BPC.1  Basic Programming Concepts

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

Page 13: BPC.1  Basic Programming Concepts

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

Page 14: BPC.1  Basic Programming Concepts

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

Page 15: BPC.1  Basic Programming Concepts

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.

Page 16: BPC.1  Basic Programming Concepts

Good programming style

1. Structured program

2. Modular design

3. Readable

4. Reusable

5. Reliable

6. Portable

7. Program documentation