Professional Documents
Culture Documents
Chapter 7 Algorithms W6
Chapter 7 Algorithms W6
1. A routine checks the weight of melons to be sold in a supermarket. Melons weighing under 0.5
kilograms are rejected and melons weighing over 2 kilograms are also rejected.
Give an example of each type of test data for this routine.
Normal ......................................................................................................................................
Extreme ....................................................................................................................................
Abnormal .............................................................................................................................. [3]
2. Read this section of program code that should input 10 positive numbers and then output the
smallest number input. [4]
1 Small = 0
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num < Small THEN Num = Small
6 Counter = Counter + 1
7 PRINT Small
8 UNTIL Counter < 10
There are four errors in this code.
Locate these errors and suggest a corrected piece of code for each error.
3. The flowchart below inputs six single digit numbers. The predefined function MOD gives the value
of the remainder, for example, Y ← 10 MOD 3 gives the value Y = 1 [4]
Complete a trace table for each of the two sets of input data.
Set 1 5, 2, 4, 3, 1, 5
Set 2 3, 2, 1, 0, 7, 3
Trace table set 1 5, 2, 4, 3, 1, 5
4. (a) Write an algorithm, using pseudocode and a FOR … TO … NEXT loop structure, to input 1000
numbers into an array. [2]
(b) Rewrite your algorithm using another loop structure. [3]
5. Using pseudocode, write an algorithm that will input the ID, weight (kg) and height (m) of 30
patients in 3 separate 1D arrays, calculate their body mass index (BMI) and prints for each patient.
----xxxxx-----