Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Chapter 7 – Worksheet 6

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

(b) State the purpose of the flowchart in part (a). [1]


(c) Identify a problem with this flowchart and explain how to correct it. [3]
Problem
Solution

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.

BMI = weight / (height)2


A BMI greater than 25 is considered overweight and a BMI less than 19 is underweight.

Output the IDs of patients who are overweight.


Output the IDs of patients who are underweight.
Output the average BMI for all 30 patients.
Output the ID of the patient with the highest and lowest BMI. [10]

----xxxxx-----

You might also like