22Flowchart
22Flowchart
Flowchart
2.1.2 Flowchart
TOTALLING
Totalling is used to calculate running total. We can use a variable such as Total or Sum to hold the
running total and assignment statements such as:
Total ← Total + Number
(new) (old)
i.e. ADD Number to (old) Total to obtain (new) Total
Count-controlled (FOR) loops
Count-controlled loop is used when the number of repetition is already known.
Example Question
a) Draw a flowchart to input 20 numbers and find the total and average of positive numbers
b) Explain how do you change your flowchart to work for 30 numbers that are between 0 and 100.
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
......................................................................................................................................................[3]
Redraw the flowchart for part b
Conditional Loop:
A loop which is executed on the basis of a condition.
Pre-condition (WHILE) loop in which condition is given at the start of loop and which is executed
only when the condition is true, is called pre-condition loop.
Post-condition (REPEAT UNTIL) loop in which condition is given at the end of loop and which is
executed only when the condition is false is called post-condition loop.
Rogue Value A value which stops input, used to terminate loop.
Q 11.8) Draw a flowchart that
Inputs the weight of a number of parcels in kilograms.
Validate parcel (parcels weighing more than 25 kilograms are rejected).
A value of –1 stops the input.
Outputs the total weight of the parcels accepted and number of parcels rejected.
Past Paper Question of same type in Summer 2015 P21& 23 Q 3
Q11.9)Summer 2009
Study the flowchart very carefully.
(a) Complete the table to show what outputs you would expect for the two inputs.[2]
Input N Output T
5
1
(b) Write down a possible LOOP construct for the section A to B in the flowchart using pseudo
code.
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
……………………………………………………………………………... [2]
Q 11.10) Draw an algorithm using flowchart that:
Inputs the height of children who want to ride on a rollercoaster
Validates height children under 1.2 metres are rejected.
When eight children have been accepted, outputs message “Ready to go” and number of
children rejected.
Complete a trace table for each of the two input values 33 and 75. [4]
Trace table for input value 33
X A B OUTPUT
X A B OUTPUT
Trace the flow chart using the numbers 2 and 3. Write down each of the values of N in the order that
they are printed out.
(a) 2 ................................................................................................................................[1]
(b) 3 ....................................................................................................................................[2]
Q11.22)Summer 2007
Study the following flowchart very carefully.
(a) Complete the following table showing the expected output from the flowchart for the three
sets of input data: [3]
INPUT X OUTPUT S
48
9170
- 800
(b) The above algorithm has been placed in a library of routines. Give one advantage of doing this.
………………………………………………………………………..................................…………………
.…………………………………………………………………………………………………………[1]
Q 11.25)Winter 2009. P11
Study the flowchart.
Complete the table to show what outputs you would expect for the three inputs. [3]
INPUT N OUTPUT C
55
2100
1
Q 11.26) Summer 2010 P12
Study the following flowchart very carefully:
What output would you expect if the following data was input into the flowchart? [3]
X OUTPUT
-150 1
540 3
0 Error
`