Professional Documents
Culture Documents
Flowchart Excerise Answers 2
Flowchart Excerise Answers 2
Algorithms
An algorithm is a precise step-by-step set of instructions for solving a problem or carrying out a task
They are often used to improve efficiency by removing the need for human input
A computer following an algorithm can decide what decision to make far more quickly than a human
Book
Algorithms
On the next four slides we will look at the same algorithm written in each method
Types of Algorithms
1 Written Description
Book
Types of Algorithms
2 Flowchart
A graphical method of showing the flow of information using a series of symbols and arrows
Book
Types of Algorithms
3 Pseudocode
Uses structured English and keywords with a heavy focus on the order of the instructions (the logic)
Book
Types of Algorithms
4 Program Code
Book
Algorithms
Link: https://www.youtube.com/watch?v=McM9YCeyt_Q
Flowcharts
Start Terminal
Start Terminal
Print “Hello
Output
world” Print “Mr” Output
End Terminal
Print “Lyon” Output
End Terminal
Book
Flowcharts
Start Terminal
Process
Alarm Rings
Ready NO
Hit snooze
to get Process
button
up? Decision
YES
End Terminal
Book
Flowcharts
Start Terminal
Input mark1,
mark2, mark3
Input
Decision
NO
Is mark1 > Is mark2 > NO
mark2? mark3?
Decision
YES YES Output Output
NO Output Output
Output Is mark1 > mark2 mark3
Output mark3 mark3?
Decision
YES
End End
End
Output
Terminal Terminal
Terminal mark1 Output
Start
No
Has the
Boil kettle water boiled?
Yes
Add tea bag Add tea bag
Add milk
End
Why do we need to use flowcharts?
• Plan a New Project
On the next slide is a flowchart used by a theme park to calculate how much a group of people should pay for entry
Part 1
Flowcharts
1
Start 2
Example YES
Is age >=
Flowchart Charge = 0 60? Charge = £9
(Difficult 2) Total = 0
Number = 0 NO
Is there YES
Charge = £10 another
Number = Number + 1 customer in
the group?
NO
Input age
YES
Is Number
> 4? Total = Total - £10
YES
Is age < Charge = £5 NO
13? Number = Number - 1
Output
Total
NO
Part 2 1 2
End
Activity 1
2 Label where each of the three constructs (sequence, selection and iteration) are used
3 Describe how the algorithm calculates the total amount that should be paid
The Smith family are visiting the park. The family consists of two children, one aged 8 and one aged 10, their two
4
parents and their grandfather, who is aged 65. Use the algorithm to calculate how much the family should pay
Part 3
Activity 2- Draw a flowchart for Guessing a Number Between 1 and 20
Pseudocode
Does not use strict syntax, it just needs to be clear and consistent
Book
Pseudocode
Use of Pseudocode
Uses commands, keywords and structures similar to those found in computer languages
Cannot be understood by computers, but is used to develop the logic of a program without needing to worry about the
syntax
A human can follow the logic of an algorithm even if there are spelling mistakes, missing brackets or quotation marks
etc.
A solution in pseudocode can then be converted into a high-level language such as Python
Sheet
Worked Example-write the Pseudocode for the flowchart
Start
Output END
total
End
Worked Example
Flowchart Pseudocode
Purpose of an Algorithm
Pseudocode Explanations
SET parcel to ‘y’ While loop ensures the program keeps running
WHILE parcel = ‘y’ DO
RECEIVE weight FROM (FLOAT) KEYBOARD User enters the weight of the parcel
IF weight <= 2 THEN
SET cost TO 2 If/else statement to work out the cost of the
ELSE parcel depending on if the weight is above or
SET excess TO weight – 2 below 2
SET cost TO 2 + (excess * 3)
END IF
SEND cost TO DISPLAY Outputs the final cost depending on the weight
SEND ‘press y for another parcel’ TO DISPLAY User is asked if they wish to run the program again
RECEIVE parcel FROM (STRING) KEYBOARD
END WHILE Programs ends if ‘y’ is not entered
Activity 3-Pseudocode
Start
Enter name
Enter your name
Enter your favourite colour Enter colour
End
Activity 4-Pseudocode
Start
…….
Enter age
….
Enter your age
NO
If the age is larger than 17 set If age >
type = child
17
the type to adult
Output
Else if the age is less than or YES ‘child’
equal to 17 set the type to type = adult
End
child
Output
Display the type ‘adult’
End
Exercise 5- write Pseudocode for the flowchart
Pseudocode
Start Terminal
Decision
Does Output
guess =
number?
“unlucky, try
NO Output
again”
YES
Output
“well done” Output
End Terminal
Activity6
Start Terminal
Write down an algorithm for making a cup of tea
Fill up and turn
kettle on Process
Process
Kettle
NO
boiled? Wait longer
Decision
YES
Add tea bag and pour
Process
water into cup
End Terminal
Sheet
Extension task Create a flowchart and a Pseudo code for the game Rock,
Scissor and paper
Algorithms
Purpose of an Algorithm
Purpose of an Algorithm
ACTIVITY
Start
- processes
weight = weight - decisions
of parcel - terminals
- iteration
is NO - input/outputs
weight Output
cost = 2
>2 cost
YES
excess
= weight - 2
cost
= 2 + (excess * 3)
Algorithms
Purpose of an Algorithm
ACTIVITY
Start Terminal
- processes
Iteration - decisions
weight = weight
of parcel Process - terminals
- iteration
Decision
is NO - input/outputs
weight Output
cost = 2
>2 cost
YES Process
Output
excess
Process
= weight - 2
cost
= 2 + (excess * 3) Process
Algorithms
Purpose of an Algorithm
Flowchart Pseudocode
Purpose of an Algorithm
Pseudocode Explanations
SET parcel to ‘y’ While loop ensures the program keeps running
WHILE parcel = ‘y’ DO
RECEIVE weight FROM (FLOAT) KEYBOARD User enters the weight of the parcel
IF weight <= 2 THEN
SET cost TO 2 If/else statement to work out the cost of the
ELSE parcel depending on if the weight is above or
SET excess TO weight – 2 below 2
SET cost TO 2 + (excess * 3)
END IF
SEND cost TO DISPLAY Outputs the final cost depending on the weight
SEND ‘press y for another parcel’ TO DISPLAY User is asked if they wish to run the program again
RECEIVE parcel FROM (STRING) KEYBOARD
END WHILE Programs ends if ‘y’ is not entered
Algorithms
Purpose of an Algorithm