You are on page 1of 5

Chapter Four

Program Development
 Program: set of instructions, which enable computers to perform a required operation.

 Types of Instructions:

a. Input/Output (I/O) Instructions: implement the transfer of data between peripherals and memory.

b. Arithmetic and Logic Instructions: implement arithmetic and comparison/logic operations.

c. Transfer of Control or Branch Instructions: transfer program control.

d. Storage/Retrieval Instructions: transfer data between accumulator and memory, i.e. copying data from
one storage location into another and retrieve as needed.

Steps to write a Computer Program: Program Development

 Five Steps: The process of solving a problem by using computer.

 These steps are:

1. Defining the problem.

2. Mapping the program logic (designing the solution).

3. Coding (writing) the program.

4. Testing and Debugging the program.

5. Documenting the tasks that are done in each step.

1. Defining the Problem:

 First and the most important step of programming.

 Study the problem very well.

 Identify users’ requirements (input, output and processing).

2. Mapping Program’s Logic (Designing the Solution):

 Representing the flow of the program diagrammatically and writing program’s pseudo code.

 Draw flow of program’s logic by using flow chart symbols.

 Write program’s logic by using pseudo code.

0
Compiled by.Molalign(course Instructor) Department of Computer Science

1
 What is Flowchart? Diagram which uses a collection of symbols to show the step-by-step processing
activities and conditions needed to solve a problem.

 Pseudo Code: model of the actual code written using normal language instead of programming language.
 Conditional Statements are:

If condition then statements


If condition then statements
Else
statements
Do while condition
Statement/Block of statements
3. Coding the Program
 Writing (program’s) actual code (source code) by following vocabulary and syntax rules of a programming
language.

4. Testing and Debugging:


 The programmer performs 2 tasks: Testing and Debugging:
 Testing - process of checking up the correctness of the program by entering different data.
 If the entered data generate wrong output - “bugs” or errors.

 Debugging - process of identifying and removing program’s errors (bugs).


 Two types of bugs: Syntax errors and Logical errors.
 Syntax error is caused by incorrect use of syntax of a programming Languages.

Compiled by.Molalign(course Instructor) Department of Computer Science

2
 Logical error is caused by not using correct control structures (sequencing, selection, and iteration) in the
proper manner.
 The process of testing and debugging may include:

 Proofreading printout of the program line-by-line in order to identify syntax and logic errors.
 Running the program.
 Sample data testing.
5. Documentation of overall steps of program: programmer prepares (compile) program’s documentation.

 Importance of Documentation:
 Updating program in the future;
 Problem diagnosis

 Identify and eliminate any remaining bugs


 Instructions to use program.
Example 1. Draw flow chart and write an algorithm that reads (accepts) two numbers and tells the greater/larger
number.

 Algorithm:
Step 1. Accept the values of A and B.
2. Compare A with B.
3. Display the result of step 2.

 Flowchart:

Compiled by.Molalign(course Instructor) Department of Computer Science

3
Example 2: Draw flow chart and write an algorithm that adds any two numbers and display the result.
Algorithm:
Step 1. Read the values of the two numbers (A and B)
Step 2. Add A and B
Step 3. Assign the sum of A and B to C
Step 4. Display the result (C)

Flowchart:
Start

Initialize C

Read A, B

C= A+B

Print C

End

Exercises
1. Draw flowchart and write an algorithm that finds the sum of any three numbers.(A+B+C)
2. Draw flowchart and write an algorithm that finds the product of any two numbers.(A*B)
3. Draw flowchart and write an algorithm that finds the square of a number.(X2)
4. Draw flowchart and write an algorithm that checks whether a given number is positive or negative.
5. Draw flowchart and write an algorithm that checks whether a given number is even or odd.
6. Draw flowchart and write an algorithm that computes the square root of any positive number.
7. Draw flowchart and write an algorithm that computes the area of a circle ( ).
8. Draw flowchart and write an algorithm that computes the area of a triangle ( ).
9. Draw flowchart and write an algorithm that finds the sum of the first 10 natural numbers (1+2+3+ …. + 10)
10. Draw flowchart and write an algorithm that finds the sum of odd numbers (1+3+5 …. + 9)
11. Draw flowchart and write an algorithm that finds the sum of even numbers (2+4+6 …. + 10)

Assignment (10%): Program Development


1. Draw flowchart and write an algorithm that checks whether a given number is even or odd.
2. Draw flowchart and write an algorithm that computes the area of a triangle ( ).
Compiled by.Molalign(course Instructor) Department of Computer Science

4
3. Draw flowchart and write an algorithm that computes the area of a circle ( ).
4. Write the algorithmic and draw a flow chart to find sum of the first 50 natural numbers (1+2+3+…. + 50).
5. Draw flowchart and write an algorithm that finds the sum of even numbers (2+4+6+ …. + 10)

Compiled by.Molalign(course Instructor) Department of Computer Science

You might also like