Computer Programing Lecture 2
Computer Programing Lecture 2
Lecture 2 (Part I)
Outlines
• Problems
• Common Steps in Problem Solving
• Solution Representations
• Pseudocode
• Flowchart
• Solving sequential computational problems
• Selection
Problems
• Flowchart types:
• Program flowchart: They contain the steps of solving a problem unit for a specific result.
• System flowchart: contain the solutions of many problem units together that are closely related to each
other and interact with each other to achieve a goal.
Program flowchart
• A program flowchart is an extremely useful tool in program development.
• Any error or omission can be more easily detected from a program flowchart than it can be from a
program because a program flowchart is a pictorial representation of the logic of a program.
• It serves as a type of documentation, which may be of great help if the need for program modification
arises in future.
Flowchart Symbols
Symbol Name and descriptions
The first five students to complete both exercises correctly get 1 bonus mark
More flowchart symbols
Symbols Name and description
Predefined processing: used to indicate any
process not specially defined in the flowchart
• The program logic should depict the flow from top to bottom and from left to right.
• Each symbol used in a program flowchart should contain only one entry point and one exit
point, with the exception of the decision symbol. This is known as the single rule.
The first 5 students to return correct answer for the questions get 1 bonus mark
Selection
Goal: Determine loss or profit
Input CP,SP
If CP <= SP
Then
If CP = SP
Then print “No profit or loss”
Else
Compute P <- SP – CP
print “The profit is ”, p
End-if
Else
Compute L <- CP – SP
print “The loss is ”, L
End-if
Stop
More Selection Exercise
- Write a pseudocode to determine the maximum of 3 numbers
- Draw a flowchart for the pseudocode
The first 5 students to complete the exercise with a correct answer get bonus 1 mark