Chapter 1-Program Design
Chapter 1-Program Design
Chapter 1-Program Design
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
Objectives
Learning Outcomes
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
Analysis
It involves identifying the inputs to the problem, the expected
outputs and any special conditions or constraints imposed
Then, a relationship between the input and output data is
established
For computing problems, appropriate formulae might be used
to relate the input and output data
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
Testing
To discover bugs or defects of the software, and do the necessary
corrections to eliminate these errors
Different sets of test data should be provided for testing
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
10
Algorithms (2/3)
Sequential execution
Instructions executed one after another in the sequence in which
they are written
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
11
Algorithms (3/3)
Structured programming: All program can be written in
terms of three control structures
Sequence structure: Instructions are executed sequentially by
default
Selection structure: A condition is tested; the next instruction to be
executed is selected from two or more options based on the truth
value of the condition
Repetition structure: A condition is tested; a block of instructions is
repeated as long as the condition remains true
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
12
Pseudocode
It is one of the most commonly used design tools for
developing algorithms
It is an imitation of the actual computer instructions
It is not actually executed on computers
It consists of actions statements
input or output operations, assignment statements, calculations
and data manipulations, function calls, etc
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
13
Flowcharts (1/2)
A flowchart is a graphical representation of an algorithm
Each steps of an algorithm are illustrated as boxes of
various special-purpose symbols connected by arrows
The order in which actions are to be performed is indicated by the
arrows
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
14
Flowcharts (2/2)
Commonly used symbols:
Symbol
Description
Oval or start and end symbol
It indicates the beginning or end of a
program, or a section of code
Rectangle or action symbol
It indicates any types of action
Diamond or decision symbol
It indicates a decision is to be made
Connector or entry and exit symbol
It connects one flowchart to another
Arrow or flowline
It shows the flow of the program
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
15
Pseudocode
16
Pseudocode
Set count to 1
While count is less than or equal to 3
Print count
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
17
(1/5)
Problem statement
Design an algorithm that inputs an arbitrary number of non-zero
positive integers and determine the sum of all odd integers read
Analysis
The problem states that an unknown number of non-zero positive
integers are expected to be received from the user. Upon receiving
these numbers, the algorithm should be able to identify all integers
having an odd value and determine the sum of all odd integers
read
Input to the problem:
integer /* a number with no fractional part */
Expected output:
sum
/* sum of all odd integers read */
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
18
(2/5)
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
19
(3/5)
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
20
(4/5)
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
21
(5/5)
Flowchart:
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
22
1.4 Summary
The Waterfall model is a commonly used software
development method
An algorithm is a sequence of instructions for carrying out
a procedure or solving a problem
An algorithm can be represented in the form of
pseudocode and flowchart
Powerpoint slides to be used with C Programming for Beginners by HC Ling, SN Cheong, YK Teh,
LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)
23