Download as pdf or txt
Download as pdf or txt
You are on page 1of 182

Chapter 7: Algorithm Design and Problem Solving

Analysis Design
C7.1
Program
Development
Life Cycle
Coding Testing

IGCSE Computer Science


Analysis
Is this what my
client want?
• •

Coding
Testing
• •
Chapter 7: Algorithm Design and Problem Solving

Analysis Program Design


Development
Coding Testing
Life Cycle
Program
Development

Cycle
Life
C7.2 - System,
sub-system
and Structured Diagram
Computer system


Computer system
Example
• Made up of software,
data, hardware,
communications and
people.
• Each computer system
can be divided up into a
set of sub-systems
• Each sub-systems can be
further divided into sub-
systems and so on until
each sub-system just
performs a single
action.
Computer system Example

• Made up of software,
data, hardware,
communications and
people.
• Each computer system
can be divided up into a • Software - the code
set of sub-systems • Data - users' preference (like and
• Each sub-systems can be follow)
further divided into sub-
• Hardware - server to store all the
systems and so on until
data (posts, stories, etc)
each sub-system just
performs a single
• Communication and people -
action. instagram's employees
Computer system Example

• Made up of software,
data, hardware,
communications and
people.
• Each computer system
can be divided up into a
set of sub-systems
• Each sub-systems can be
further divided into sub-
systems and so on until
each sub-system just
performs a single
action.
post story reel
Computer system
Normal
• Made up of software,
data, hardware,
communications and
people.
• Each computer system
can be divided up into a
set of sub-systems
• Each sub-systems can be
further divided into sub-
systems and so on until story
each sub-system just Close
performs a single friends
action.
Other examples of a
computer system


to aspiring programmer

Before you build something, figure out what you


want to build first.
Components of a
computer system




Understanding the components of a computer
system will help us to break down problem easier.
if i were to create a software today...

How do I divide my system into sub-system and


sub-system?

How do I then start developing a sub-


system using an appropriate programming
language?
Use software design tools

How do I divide my system into sub-system and


sub-system?

How do I then start developing a sub-


system using an appropriate programming
language?
Structured diagram

Top-down design
Structured diagram in application
(alarm clock)
Alarm Clock
Structured diagram in application
(alarm clock)
Alarm Clock

Inputs Outputs
Processes
Structured diagram in application
(alarm clock)
Alarm Clock

Inputs Outputs
Processes

Set Time
Turn alarm
Check Time Sound Turn off
on and off
Alarm alarm
Definition of algorithm

An algorithm is a set of
instructions for solving a
problem or accomplishing a task.
Example of an algorithm (Real Life)
Example of an algorithm (Real Life) - Driving a car

Walk to the
parking space Letgoooo!

Open the door


Put on your
seatbelt

Turn on the
engine
Example of an algorithm (Software) - Alarm clock

For every 1 second,


check if time match

Alarm will ring


if time match,check
if day match (eg.
weekday

If both matches,
send signal to
sound system
Flowchart and pseudocode are an effective way to
communicate how the algorithm that makes up a
system or a sub-system work.
Flowchart and pseudocode are an effective way to
communicate how the algorithm that makes up a
system or a sub-system work.
Have a look at a
flowchart showing
how the checking for
the alarm time
subsystem works, can
you understand what
is it doing?
Components of a flow chart
Terminator process Input/output
Used at the Show the input of
Represent an
beginning and end data and output
instruction
of each flowchart of information
No matter how Protecting the
small the environment is
ecosystem on the same as
earth, everything protecting the
is interconnected ecosystem
Components of a flow chart
Decision
• Used to decide which action is to be taken
next
• There are always two outputs from a decision
flowchart symbol
Components of a flow chart

subroutine Flowline
• Represents a smaller • Use arrows to show the
procedure running within direction of flow
the large program.
• Abstraction in action

• Could be
another
flowchart
defined
elsewhere
Input/
output

Terminator
subroutine

process
Decision
A computer program allows a user to
input two numbers. It multiplies the
Analysis
numbers together and if the answer is
larger than 100 it outputs the message Input:
"Greater than 100". The program loops
until the user does not want to input
Output:
any more numbers. Process:
Draw a flowchart that represents an
algorithm for the computer program.
A computer program allows a user to
Analysis
input two numbers. It multiplies the
numbers together and if the answer is Input: Number 1 & 2
larger than 100 it outputs the message
"Greater than 100". The program loops
Output: Message >100
until the user does not want to input
any more numbers.
Process:
- if N1 + N2 > 100,
Draw a flowchart that represents an
algorithm for the computer program. output message >100
- process continue until
user does not want to
input numbers
A computer program allows a user to
input two numbers. It multiplies the
numbers together and if the answer is
larger than 100 it outputs the message
"Greater than 100". The program loops
until the user does not want to input
any more numbers.

Draw a flowchart that represents an


algorithm for the computer program.
Tickets are sold for a concert at $20
each, if 10 tickets are bought then the
discount is 10%, if 20 tickets are
bought the discount is 20%. No more
than 25 tickets can be bought in a
single transaction.

You are asked to design a program


that can automatically calculate the
cost of the purchase. Draw a flowchart
for this program.
Analysis
Tickets are sold for a concert at $20 Input:
each, if 10 tickets are bought then the
discount is 10%, if 20 tickets are
Output:
bought the discount is 20%. No more
than 25 tickets can be bought in a
Process:
single transaction.

You are asked to design a program


that can automatically calculate the
cost of the purchase. Draw a flowchart
for this program.
Analysis
Tickets are sold for a concert at $20 Input: Number of tickets
each, if 10 tickets are bought then the
discount is 10%, if 20 tickets are
(limit = 25)
bought the discount is 20%. No more
than 25 tickets can be bought in a
Output: Total cost
single transaction. Process:
You are asked to design a program 10 tickets = 10% discount
that can automatically calculate the
cost of the purchase. Draw a flowchart 20 tickets = 20% discount
for this program.
Input/
output

Terminator

Tickets are sold for a concert at $20


each, if 10 tickets are bought then the
discount is 10%, if 20 tickets are
Decision bought the discount is 20%. No more
than 25 tickets can be bought in a
single transaction.

subroutine You are asked to design a program


that can automatically calculate the
cost of the purchase. Draw a flowchart
for this program.
process

Flow chart components


Tickets are sold for a concert at $20
each, if 10 tickets are bought then the
discount is 10%, if 20 tickets are
bought the discount is 20%. No more
than 25 tickets can be bought in a
single transaction.

You are asked to design a program


that can automatically calculate the
cost of the purchase. Draw a flowchart
for this program.









• ←
• ←
• ←
• ←
• ←










































Totalling






Say,we want to search for a
student called Lyn ..
Found!

The algorithm will go through the value in the


array one by one until it finds the target OR it
reaches the end of the list.




Find this video on YouTube for a
thorough explanation!






C7.6

VALIDATION AND
VERIFICATION
James Gan
IN ORDER FOR COMPUTER SYSTEMS TO ONLY ACCEPT DATA INPUTS THAT ARE
REASONABLE AND ACCURATE, EVERY ITEM OF DATA NEEDS TO BE EXAMINED
BEFORE IT IS ACCEPTED BY THE SYSTEM.

VALIDATION VERIFICATION
VALIDATION
VALIDATION
Range
DEFINITION
Check
A RANGE CHECK CHECKS THAT THE VALUE OF A NUMBER
IS BETWEEN AN UPPER VALUE AND A LOWER VALUE
VALIDATION
Range
Check
VALIDATION
length
Check
DEFINITION
A LENGTH CHECK EIHTER CHECKS THAT DATA CONTAINS
- AN EXACT NUMBER OF CHARACTERS (EG. 8)
- THE DATA ENTERED IS A REASONABLE NUMBER OF CHARACTERS (EG. 8-20)
VALIDATION
length
Check
VALIDATION
TYPE
DEFINITION
Check
A TYPE CHECK CHECKS THAT THE DATA ENTERED IS OF A
GIVEN DATA TYPE, FOR EXAMPLE, THAT THE NUMBER OF
MEALS ORDERED MUST BE A NUMBER
VALIDATION
TYPE
Check
VALIDATION
Presence
check
DEFINITION
A PRESENCE CHECK CHECKS TO ENSURE THAT SOME DATA HAS BEEN ENTERED
AND THE VALUE HAS NOT BEEN LEFT BLANK.
VALIDATION
Presence
check
DEFINITION
A PRESENCE CHECK CHECKS TO ENSURE THAT SOME DATA HAS BEEN ENTERED
AND THE VALUE HAS NOT BEEN LEFT BLANK, FOR EXAMPLE, AN EMAIL ADDRESS
FOR AN ONLINE TRANSACTION MUST BE COMPLETED.
Format VALIDATION

check DEFINITION
A FORMAT CHECK CHECKS THAT THE CHARACTERS ENTERED CONFORM TO A
PRE-DEFINED PATTERN.
Check
digit CHECK DIGIT
Check digits are used to identify errors in data entry
caused by mis-typing or mis-scanning a barcode.
TEST YOUR
UNDERSTANDING
Discuss, what checks are required for the following validations

– Entering a telephone number


– Entering a pupil’s name
– Entering a part number in the form XXX999, when X must be a
letter and 9 must be a digit.
TEST YOUR
UNDERSTANDING
Discuss, what checks are required for the following validations

– Entering a telephone number


(answer: length check, type check, format check)
– Entering a pupil’s name
(answer: type check)
– Entering a part number in the form XXX999, when X must be a
letter and 9 must be a digit.
(answer: format check)
VERIFICATION



VERIFICATION(1) - DOUBLE ENTRY
VERIFICATION(2) - SCREEN/VISUAL CHECK
C7.7

TESTING
TESTING


DATA THAT CAN BE USED FOR TESTING

NORMAL ABNORMAL EXTREME BOUNDARY


DATA DATA DATA DATA
DATA THAT A PROGRAM WOULD EXPECT TO RECEIVE, AND
NORMAL THE RESULT THAT ARE EXPECTED FROM THE DATA.
DATA

EG. PROGRAM THAT CALCULATES THE AVERAGE


SCORE
CORRECT
AVERAGE
SCORE

NORMAL DATA THAT WOULD BE EXPECTED


ABNORMAL DATA THAT A PROGRAM SHOULD REJECT. OUR
DATA PROGRAM NEEDS TO REJECT THE ERRORNEOUS DATA

EG. PROGRAM THAT CALCULATES THE AVERAGE


SCORE
WE NEED TO INCORRECT
TEST THAT OUR AVERAGE
PROGRAM WILL
SCORE
REJECT THIS
DATA
NORMAL DATA THAT WOULD BE EXPECTED
ABNORMAL DATA THAT A PROGRAM SHOULD REJECT. OUR
DATA PROGRAM NEEDS TO REJECT THE ERRORNEOUS DATA

EG. PROGRAM THAT CALCULATES THE AVERAGE SCORE

WE NEED TO INCORRECT
TEST THAT OUR AVERAGE
PROGRAM WILL
SCORE
REJECT THIS
DATA
NORMAL DATA THAT WOULD BE EXPECTED
EXTREME EXTREME DATA ARE THE LARGEST AND SMALLEST
DATA VALUES THAT NORMAL DATA CAN TAKE

EG. PROGRAM TAKES IN USER'S INPUT FOR STUDENT'S MARK

NORMAL DATA THAT WOULD BE EXPECTED


EXTREME
DATA
BOUNDARY AT EACH BOUNDARY TWO VALUES ARE REQUIRED: ONE
DATA VALUE IS ACCEPTED AND THE OTHER VALUE IS REJECTED

SCENARIO: A PROGRAM THAT ACCEPTS


VALUE FROM RANGE 1 - 10

EXAMPLE 1 EXAMPLE 2

NORMAL + REJECTED NORMAL + REJECTED


EXTREME DATA EXTREME DATA
BOUNDARY AT EACH BOUNDARY TWO VALUES ARE REQUIRED: ONE
DATA VALUE IS ACCEPTED AND THE OTHER VALUE IS REJECTED

SCENARIO: A PROGRAM THAT ACCEPTS


VALUE FROM RANGE 4 - 15

EXAMPLE 1 EXAMPLE 2

NORMAL + REJECTED NORMAL + REJECTED


EXTREME DATA EXTREME DATA
BOUNDARY AT EACH BOUNDARY TWO VALUES ARE REQUIRED: ONE
DATA VALUE IS ACCEPTED AND THE OTHER VALUE IS REJECTED

SCENARIO: A PROGRAM THAT ACCEPTS


VALUE FROM RANGE 4 - 15

EXAMPLE 1 EXAMPLE 2

NORMAL + REJECTED NORMAL + REJECTED


EXTREME DATA EXTREME DATA
0 0 100

1 9 9 9

2 9 7 7

3 9 3 3

4 9 1 1 91
0 0 100

1 19 19 19

2 27 19 27

3 31 19 31

4 31 14 14 31 14
0 0 100

1 9 9 9

2 9 7 7

3 9 3 3

4 9 1 1 91
0 0 100
1 13 13 13

2 17 13 17

3 21 13 21

4 21 11 11 21 11
Explanation
Explanation
We can fix it - quick fix
We can fix it - quick fix
Ultimate
solution
Problem statement

Answer


create some test
data to check the ←
correctness of an
algorithm


eg.

Test data = 12
Discount = 10%
Calculation=

(12 x 20) * 0.9 =
$216

Now, go through

the algorithm to
check if it works
as expected with ←
the test data.

You might also like