Homework #08 - Questions: For To Next
Homework #08 - Questions: For To Next
Question 1
Write an algorithm, using pseudocode and a FOR … TO … NEXT loop structure, to input 1000
numbers into an array. [2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 2
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. [2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 3
A routine checks the age and height of children who are allowed to enter a play area. The children
must be less than 5 years of age and under 1 metre in height.
The first set of test data used is age 3 and height 0.82 metres. State what type of test data this is. [1]
…………………………………………………………………………………………………………
Give a reason for using this test data. [1]
…………………………………………………………………………………………………………
Provide two additional sets of test data. For each, give
the type of each set of test data
the reason why it is used
Each type of test data and reason for use must be different. [6]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 4
A program will be written to store information about members of a swimming club. The following
membership details will be recorded:
Name
Gender
Status: (Senior or Junior)
Fee
Team member (Yes or No)
Choose a suitable data type for each of the membership details to be recorded [5]
Name
Gender
Status
Fee
Team member
The swimming club has 50 members.
State the data structure that would be most suitable to use and give a reason for your choice. [2]
Reason
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 5
A programmer writes a program to store a patient’s temperature every hour for a day.
State the data structure that would be most suitable to use and give the reason for your choice. [2]
Data structure
…………………………………………………………………………………………………………
Reason
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 6
Rewrite the following pseudocode algorithm using a WHILE … DO … ENDWHILE loop. [3]
INPUT Num
FOR Counter ← 1 TO 12
Num ← Num * Counter
A[Counter] ← Num
NEXT
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 7
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Identify, using pseudocode, another loop structure that the algorithm in previous part could have
used. [1]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 8
This section of program code asks for 80 numbers between 100 and 1000 to be entered. It checks
that the numbers are in the correct range, and stores them in an array. It counts how many of the
numbers are larger than 500 and then outputs the result when the program is finished. [4]
1 Count = 0
2 FOR Index = 1 TO 80
3 INPUT 'Enter a number between 100 and 1000', Number
4 WHILE Number = 99 AND Number = 1001
5 INPUT 'This is incorrect, please try again', Number
6 ENDWHILE
7 Num[80] = Number
8 IF Number > 500 THEN Count = Count + 1
9 UNTIL Index = 80
10 PRINT Index
11 PRINT ' numbers were larger than 500'
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 9
Write an algorithm in pseudocode, using a single loop, to print 50 names that have been stored in an
array. [3]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 10
Complete the trace table using the data given in the array.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 11
The global trade item number (GTIN-8) barcode has seven digits and a check digit.
This pseudocode algorithm inputs seven digits and calculates the eighth digit, then outputs the
GTIN-8. DIV(X,Y), finds the number of divides in division for example DIV(23,10) is 2.
MOD(X,Y), finds the remainder in division for example MOD(23,10) is 3. [6]
FOR Count ← 1 TO 7
INPUT Number
Digit(Count) ← Number
NEXT
Sum ← (Digit(1)+Digit(3)+Digit(5)+Digit(7))*3+Digit(2)+Digit(4)+Digit(6)
IF MOD(Sum,10) <> 0
THEN Digit(8) ← DIV(Sum,10)*10 + 10 - Sum
ELSE
Digit(8) ← 0
ENDIF
OUTPUT "GTIN-8"
FOR Count ← 1 TO 8
OUTPUT Digit(Count)
NEXT
Explain how you would change the algorithm to input eight digits (seven digits and the check digit)
and output if the check digit entered is correct or not. [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 12
A program checks that the weight of a basket of fruit is over 1.00 kilograms and under
1.10 kilograms. Weights are recorded to an accuracy of two decimal places and any weight not in
this form has already been rejected.
Give three weights as test data and for each weight state a reason for choosing it. All your reasons
must be different. [6]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 13
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Describe how you could modify the original algorithm shown at the start of question 13, to allow
any number of inputs. [2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 14
…………………………………………………………………………………………………………
Question 15
Write an algorithm, using pseudocode, to input three different numbers, multiply the two larger
numbers together and output the result. Use the variables: Number1, Number2 and Number3 for
your numbers and Answer for your result. [5]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Give two sets of test data to use with your algorithm in part (a) and explain why you chose each
set. [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 16
A programmer wants to test that the readings from 2000 electricity meters are greater than 400 units
and less than 900 units. The programmer uses selection and repetition statements as part of the
program. Explain, using programming statements, how selection and repetition could be used in this
program. [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 17
The flowchart checks the level of chlorine and the depth of water compared to the height of the
swimming pool. Error messages are output if a problem is found. [9]
Complete the trace tables for each set of input data. Input data: 6, 2.5, 2
Input data: 4, 3, 1.5
Identify a problem with the algorithm that the flowchart represents. [2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 18
Complete the trace table for this algorithm using the given input data. [6]
Index ← 0
FOR Count ← 0 TO 7
INPUT Value
IF Value > 50 THEN
PassMarks[Index] ← Value
Index ← Index + 1
ENDIF
NEXT Count
PRINT "Number passed ", Index
…………………………………………………………………………………………………………
Question 19
Explain why constants, variables and arrays are used in programming. [6]
Constants
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Variables
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Arrays
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 20
The algorithm performs an operation on the array named MyData
DIV means integer division, so only the whole number part of the result is returned
e.g. 7 DIV 2 returns a value of 3
First ← 0
Last ← 16
Found ← FALSE
INPUT UserIn
WHILE (First <= Last) AND (Found = FALSE) DO
Middle ← (First + Last) DIV 2
IF MyData[Middle] = UserIn THEN
Found TRUE
ELSE
IF UserIn < MyData[Middle] THEN
Last ← Middle – 1
ELSE
First ← Middle + 1
ENDIF
ENDIF
ENDWHILE
OUTPUT Found
This table shows the contents of the array: MyData e.g. MyData[2] stores the value 5
[6]
…………………………………………………………………………………………………………
Question 21
The pseudocode algorithm shown should allow numbers to be entered and should allow 50 numbers
to be stored in an array.
Count ← 0
REPEAT
INPUT Values[Count]
Count ← Count + 1
UNTIL Count = 0
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Re-write the original pseudocode so that it terminates correctly and also prevents numbers
below 100 from being stored in the array Values[ ]
Count ← 0
REPEAT
INPUT Number
IF Number >= 100 THEN
Values[Count] ← Number
ENDIF
Count ← Count + 1
UNTIL Count = 50
Describe how you could change your pseudocode in previous part so that it prevents numbers
below 100 and above 200 from being stored in the array Values[ ] [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 22
The flowchart represents an algorithm.
The predefined function DIV gives the value of the result of integer division,
for example, y ← 9 DIV 4 gives y a value of 2
An input value of –1 ends the algorithm.
Complete the trace table for the input data:
50, 33, 18, 15, 30, –1, 45, 12, 90, 6
[4]
Describe the purpose of the algorithm. [2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 23
An algorithm has been written in pseudocode to input the names and marks of 35 students.
The algorithm stores the names and marks in two arrays Name[ ] and Mark[ ]. The highest
mark awarded is found and the number of students with that mark is counted. Both of these
values are output.
01 HighestMark ← 100
02 HighestMarkStudents ← 0
03 FOR Count ← 1 TO 35
04 OUTPUT "Please enter student name"
05 INPUT Name[Count]
06 OUTPUT "Please enter student mark"
07 INPUT Mark[Counter]
08 IF Mark[Count] = HighestMark
09 THEN
10 HighestMarkStudents ← HighestMarkStudents – 1
11 ENDIF
12 IF Mark[Count] > HighestMark
13 THEN
14 Mark[Count] ← HighestMark
15 HighestMarkStudents ← 1
16 ENDIF
17 NEXT Count
18 OUTPUT "There are ", HighestMarkStudents," with the highest
mark of ",HighestMark
Give line numbers where the four errors are to be found in the pseudocode. Suggest a
correction for each error [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Explain how you could extend the algorithm to also find the lowest mark awarded, count the
number of students with that mark, and output both these values. [3]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 24
This flowchart inputs the points won and the points lost when playing a game. The difference
between the points won and lost is calculated and depending on the result the player can: move
up to the next level, stay at the same level, or move down to the previous level. The flowchart
finishes when the input for points won is –1.
Complete a trace table for this set of input data:
5000, 4474, 6055, 2000, 7900, 9800, 3000, 2150, –1, 6700, 7615
The flowchart needs to be changed. When the difference is more than 5000 the output message is
‘Fantastic leap up two levels’.
Describe the changes that will need to be made to the flowchart. [3]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 25
Arrays are data structures used in programming. Explain what is meant by the terms dimension
and index in an array. Use examples of arrays in your explanations. [3]
Dimension
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Index
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 26
An algorithm has been written in pseudocode to input 50 numbers. Positive numbers are stored in
the array PosNum [ ]. Negative numbers are stored in the array NegNum[ ]. Zeros are not
included in the positive and negative counts.
Count ← 0
PosCount ← Count
NegCount ← Count
REPEAT
INPUT Number
IF Number > 0 THEN
PosCount ← PosCount + 1
PosNum[PosCount] ← Number
ELSE
NegCount ← NegCount + 1
NegNum[NegCount] ← Number
ENDIF
Count ← Count + 1
UNTIL Count >= 50
OUTPUT "There are ", PosCount," positive numbers"
OUTPUT "There are ", NegCount," negative numbers"
Describe the error in the pseudocode and write the correction for this error. [4]
Error:
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Correction:
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
The algorithm needs to be changed so there is no limit to how many numbers can be input.
When the number 9999 is input, the algorithm stops more numbers being input and outputs the
results. The number 9999 is not to be stored nor counted as a positive number.
Explain how you would change the algorithm. [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 27
This pseudocode algorithm allows 5000 numbers to be entered and stored in an array called
Number.
FOR Count ← 1 TO 5000
INPUT Number[Count]
NEXT Count
Extend and re-write the algorithm using pseudocode to also count and output how many of the
numbers stored in the array are greater than 500, using the variable Higher. Only output Higher
once with an appropriate message. [6]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 28
REPEAT
Flag ← 0
FOR Count ← 0 to 3
IF Num[Count] < Num[Count + 1] THEN
Store ← Num[Count]
Num[Count] ← Num[Count + 1]
Num[Count + 1] ← Store
Flag ← 1
ENDIF
NEXT Count
UNTIL Flag = 0
Complete the trace table for the algorithm using the data given in the array. [5]
…………………………………………………………………………………………………………
Question 29
The pseudocode algorithm shown has been written by a teacher to enter marks for the students in
her class and then to apply some simple processing.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Write the pseudocode to output the contents of the arrays Score[] and Grade[] along with
suitable messages. [3]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Describe how you could change the algorithm to allow teachers to use it with any size of class. [3]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 30
Write a pseudocode routine that sets each element to zero. Use the most suitable loop structure. [3]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Explain why you chose this loop structure. [2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 31
The pseudocode algorithm should allow a user to input the number of scores to be entered and then
enter the scores. The scores are totalled, the total is output and the option to enter another set of
scores is offered.
1 Count ← 0
2 REPEAT
3 FullScore ← 20
4 INPUT Number
5 FOR StoreLoop ← 1 TO Number
6 INPUT Score
7 FullScore ← FullScore
8 UNTIL StoreLoop = Number
9 OUTPUT "The full score is ", FullScore
10 OUTPUT "Another set of scores (Y or N)?"
11 OUTPUT Another
12 IF Another = "N"
13 THEN
14 Count ← 1
15 ENDIF
16 UNTIL Count = 1
Identify the four errors in the pseudocode and suggest a correction for each error. [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Show how you could change the algorithm to store the individual scores in the array
ScoreArray[], then find and print the average score once the scores have all been entered. [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 32
…………………………………………………………………………………………………………
Suggest an addition that could be made to the algorithm to make it more useful. [1]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 33
Explain why constants, variables and arrays are used in programming. [6]
Constants
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Variables
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Arrays
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 34
An algorithm has been written in pseudocode to generate 50 positive random integers with values
less than or equal to 100. These random integers are stored in the array RandNum[ ]
The function Rand(X, Y) generates a random integer greater than or equal to X and less than Y.
For example, Rand(1, 4) generates 1 or 2 or 3.
Find the four errors in the pseudocode and write a correction for each error. [4]
1 Count 0
2 REPEAT
3 RandNum[Counter] Rand(1, 100)
4 Count Count + 2
5 UNTIL Count <= 50
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
The pseudocode for this algorithm could be shortened by the use of a FOR … NEXT loop. Rewrite
the algorithm using a FOR … NEXT loop. [3]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
The flowchart shows an algorithm that should allow 60 test results to be entered into the variable
Score. Each test result is checked to see if it is 50 or more. If it is, the test result is assigned to the
Pass array. Otherwise, it is assigned to the Fail array.
Complete this flowchart:
Write a pseudocode routine that will check that each test result entered into the algorithm is
between 0 and 100 inclusive. [4]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 36
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Explain how indexing could be used to search for a value stored in a one-dimensional array. [2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 37
Count ← 0
INPUT Limit
FOR In ← 1 TO Limit
Logic ← TRUE
Test ← 2
INPUT Number
REPEAT
IF Number / Test = Number DIV Test THEN
Logic ← FALSE
ELSE
Test ← Test + 1
ENDIF
UNTIL NOT Logic OR Test >= Number DIV 2
IF Logic THEN
Store[Count] ← Number
Count ← Count + 1
ENDIF
NEXT In
FOR Out ← 0 TO Count - 1
OUTPUT Store[Out]
NEXT Out
Complete the trace table for the algorithm using this input data:
5, 9, 5, 8, 10, 7
[7]
State the purpose of this algorithm. [2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
This algorithm only works for numbers that are 3 or greater.
Describe how you could change this algorithm to make sure that only numbers that are 3 or greater
are entered. Any pseudocode statements used in your answer must be fully described. [3]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Validations , Top-Down-Design and Life Cycle Questions
Question 1
A programmer restricts input values to less than 90 and greater than 60.
State whether this is called validation or verification.
……………………………………………………………………………………………………...[1]
Name the check that needs to be used.
……………………………………………………………………………………………………...[1]
State three different types of test data the programmer would need to use. Give an example
of each type and the reason that the programmer chose that test data.
Type 1
………………………………………………………………………………………………………....
Example
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Type 2
………………………………………………………………………………………………………....
Example
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Type 3
………………………………………………………………………………………………………....
Example
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[9]
Question 2
[3]
Draw a flowchart to represent this section of program code. [5]
Question 3
Programs can perform validation and verification checks when data is entered. Give the names of
two different validation checks and state the purpose of each one.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………..[4]
Give the name of one verification check.
……………………………………………………………………………………………………..[1]
Describe the difference between validation and verification.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………..[2]
Question 5
A code must take the form LL9 9LL where L is a letter and 9 is a digit
A presence check has already been used to ensure data has been entered. Name two other types of
validation check that can be used to test the code is valid.
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Give one example of invalid test data for each of the validation checks you have named in previous
question and in each case, give a reason why it fails the check. Each example of test data must be
different.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
Question 6
Explain why validation and verification checks are needed when data is input.
Include an example of each type of check in your answer.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
Question 7
Describe, giving a different example for each, the purpose of these validation checks used in
programming.
Range check
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Example
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Length check
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Example
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Type check
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Example
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 9
A programmer has written a routine to check that prices are below $10.00. These values are used as
test data. [3]
10.00 9.99 ten
Explain why each value was chosen.
10.00
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
9.99
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
ten
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[3]
Question 10
A programmer has written a routine to store the name, email address and password of a contributor
to a website’s discussion group.
The programmer has chosen to verify the name, email address and password. Explain why
verification was chosen and describe how the programmer would verify this data.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
The programmer has also decided to validate the email address and the password. Describe
validation checks that could be used.
Email address
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Password
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
A program checks that the weight of a basket of fruit is over 1.00 kilograms and
under 1.10 kilograms. Weights are recorded to an accuracy of two decimal places and any weight
not in this form has already been rejected. Give three weights as test data and for each weight state a
reason for choosing it. All your reasons must be different.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[3]
Question 11
Describe, using an example, the purpose of the following checks during data entry.
Validation check
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………........
Verification check
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
Question 12
A satellite navigation system works using destination details entered by the user, either a new
destination or chosen from previously saved destinations. The satellite navigation system will then
output directions to the destination in the form of either a visual map or a list of directions. A
satellite navigation system is an example of a computer system that is made up of sub-systems. This
structure diagram shows some of its sub-systems. Complete the diagram by filling in the empty
boxes. [2]
Question 15
Identify three different types of test data. For each type, give an example of the test data you would
use to test this algorithm and state a reason for your choice of test. [6]
Type of test data 1
………………………………………………………………………………………………………....
Test data
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Type of test data 2
………………………………………………………………………………………………………....
Test data
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Type of test data 3
………………………………………………………………………………………………………....
Test data
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 16
Identify a suitable validation check that could be used for each piece of normal test data and
describe how it would be used. Each validation check must be different.
Test data for entering an email address: [email protected]
Validation check name
………………………………………………………………………………………………………....
Description of use
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Test data for entering a year: 2021
Validation check name
………………………………………………………………………………………………………....
Description of use
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Test data for entering a name: Ericson-Bower
A program has been written to check the value of a measurement. The measurement must be a
positive number and given to three decimal places, for example, 3.982. State suitable examples of
normal and erroneous test data that could be used to test this program. For each example give the
reason for your choice of test data.
Normal test data example
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Erroneous test data example
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
Explain why two pieces of boundary test data are required for this program. Give an example of
each piece of boundary test data.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[3]
Explain why verification is needed and how verification could be performed by this program.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[3]
Question 18
A program checks that the data entered is between 1 and 100 inclusive.
Identify one piece of normal, extreme and erroneous test data for this program, and give a reason
for each.
Normal test data
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Extreme test data
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Erroneous test data
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 19
A program has been written to check the length and content of a password. The password must be
eight or more characters long and contain at least one special character, for example, Secret!*!
State suitable examples of normal and erroneous test data that could be used to test this program.
For each example give the reason for your choice of test data.
Normal test data example
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Erroneous test data example
………………………………………………………………………………………………………....
Reason
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
Explain why two pieces of boundary test data are required for this program.
Give an example of each piece of boundary test data.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[3]
Describe two methods of verification that could be used to verify this data as it is input.
Method 1
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Method 2
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
Question 20
Question 01
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[7]
Question 3 (Challenge)
A programmer is writing a treasure island game to be played on the computer. The island is a
rectangular grid, 30 squares by 10 squares. Each square of the island is represented by an element
in a 2D array. The top left square of the island is represented by the array element [0, 0]. There are
30 squares across and 10 squares down.
The computer will:
generate three random locations where treasure will be buried
prompt the player for the location of one square where the player chooses to dig
display the contents of the array by outputting for each square:
'.' for only sand in this square
'T' for treasure still hidden in sand
'X' for a hole dug where treasure was found
'O' for a hole dug where no treasure was found.
Here is an example display after the player has chosen to dig at location [9, 3]:
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[1]
Write pseudocode to declare a constant called SAND and assign the value '.' to it
……………………………………………………………………………………………………...[1]
Step 2
Complete the missing pseudocode statement for the InitialiseGrid()procedure. [4]
PROCEDURE InitialiseGrid()
DECLARE X, Y : INTEGER
FOR X ← 0 TO ……………………
FOR Y ← 0 TO ……………………
Grid[X,Y] ← ……………………
……………………
NEXT X
ENDPROCEDURE
Step 3
Complete the missing pseudocode statement for the DisplayGrid()procedure. [4]
PROCEDURE DisplayGrid()
DECLARE R, C : INTEGER
FOR R ← 0 TO ……………………
FOR C ← 0 TO ……………………
……………………
……………………
NEXT X
ENDPROCEDURE
Step 4
HideTreasure()
Generates a pair of random numbers used as the grid location of treasure and marks the
square with 'T'
Use RAND (x : INTEGER) RETURNS REAL returns a real number in the range 0 to x
(not inclusive of x) Example: RAND(87) could return 35.43
Write Pseudocode for the HideTreasure procedure. Your procedure should check that
the random location generated does not already contain treasure. The value to represent
treasure should be declared as a constant.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[5]
Step 5
DigHole(Row, Col)
Takes as parameters a valid grid location and marks the square with 'X' or 'O' as
appropriate
Write program code for the DigHole procedure. The values to represent treasure, found
treasure and hole should be declared as constants
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[5]
Step 6
StartDig()
Write pseudocode for the StartDig procedure. Ensure that the user input is fully validated.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[5]
Step 7
Now it is the fun part, the main program is designed as follows to give execution to all the previous
procedures and you can play the game !!!!!
CALL InitialiseGrid()
CALL DisplayGrid()
FOR i ← 1 TO 3
CALL HideTreasure()
NEXT i
CALL StartDig()
CALL DisplayGrid()
Question 4
A program uses two 1D arrays of type integer. Array1 contains 600 elements and Array2
contains 200 elements.
Array1 contains sample values read from a sensor. The sensor always takes three consecutive
samples and all of these values are stored in Array1.
A procedure Summarise() will calculate the average of three consecutive values from Array1
and write the result to Array2. This will be repeated for all values in Array1.
The diagram below illustrates the process for the first six entries in Array1.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 5
The given algorithm is a simple bubble sort that arranges a set of scores stored in a one dimensional
array into descending order, and orders the corresponding students’ names stored into a two-
dimensional array in the same order as the scores. All the arrays are indexed from 1. The contents of
both arrays after sorting are shown.
Kris has written a program that will work out the wages for her staff. The main steps for
each employee are: to work out the hours worked, work out the total earnings, work out tax and
finally print out how much will be taken home.
Complete the structure diagram to show the modules that will be needed. [2]
The printout will be different for those staff who receive cash and those who have their earnings
paid directly to a bank account. Add the next level to the print module.
Explain how it is possible to use the same variable name for different variables in different
modules.
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[1]
Question 10
Write an algorithm using pseudocode to perform this task. (Ensure that you use meaningful variable
names)
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 11
A teacher wants to write a program to help young children learn their multiplication tables.
The teacher wants the program to:
show a visual representation of a multiplication
ask the child to key in an answer.
For example, the multiplication of 3 × 4 is represented as shown.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 12
Ahmed needs to be aware of his average mark and declares a variable with identifier MyAvMark
which he decides will be a global variable.
State where in the program a global variable will be declared.
……………………………………………………………………………………………………...[1]
Using only global variables is poor programming practice.
Give a possible problem that could result from this.
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Question 13
The 1D array StudentName[] contains the names of students in a class. The 2D array
StudentMark[] contains the mark for each subject, for each student. The position of each
student’s data in the two arrays is the same, for example, the student in position 10 in
StudentName[] and StudentMark[] is the same. The variable ClassSize contains the
number of students in the class. The variable SubjectNo contains the number of subjects studied.
All students study the same number of subjects. The arrays and variables have already been set up
and the data stored. Students are awarded a grade based on their average mark.
The following pseudocode algorithm attempts to check whether a string is a valid email address.
FUNCTION IsValid(InString : STRING) RETURNS BOOLEAN
DECLARE Index, Dots, Ats, Others : INTEGER
DECLARE NextChar : CHAR
DECLARE Valid : BOOLEAN
Index ← 1
Dots ← 0
Ats ← 0
Others ← 0
Valid ← TRUE
REPEAT
NextChar ← SUBSTRING(InString, Index, 1)
CASE OF NextChar
'.' : Dots ← Dots + 1
'@' : Ats ← Ats + 1
IF Ats > 1 THEN
Valid ← FALSE
ENDIF
OTHERWISE : Others ← Others + 1
ENDCASE
IF Dots > 1 AND Ats = 0 THEN
Valid ← FALSE
ELSE
Index ← Index + 1
ENDIF
UNTIL Index > LENGTH(InString) OR Valid = FALSE
IF NOT (Dots >= 1 AND Ats = 1 AND Others > 8) THEN
Valid ← FALSE
ENDIF
RETURN Valid
ENDFUNCTION
State the values that would result in the condition evaluating to TRUE.
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Complete the trace table by dry running the function when it is called as follows: [5]
Result ← IsValid("Liz.123@big@net")
State the value returned when IsValid() is called using the previous expression
……………………………………………………………………………………………………...[1]
Question17
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question18
The factorial of a number is the product of all the integers from 1 to that number.
For example:
factorial of 5 is given by 1 × 2 × 3 × 4 × 5 = 120
factorial of 7 is given by 1 × 2 × 3 × 4 × 5 × 6 × 7 = 5040
factorial of 1 = 1
Note: factorial of 0 = 1
A function Factorial() will:
be called with an integer number as a parameter
calculate and return the factorial of the number
return −1 if the number is negative.
Write pseudocode for the function Factorial().
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
A procedure FirstTen() will output the factorial of the numbers from 0 to 9. The procedure will
use the function from previous part
The required output is:
Factorial of 0 is 1
Factorial of 1 is 1
Factorial of 2 is 2
.
.
.
Factorial of 9 is 362880
Complete the table by writing the text that should replace each label A to F. [6]
Label Text
F
Question19
A program is to be written which accepts a string and then calculates a numeric value from this
string. The input string and the calculated value are then to be sent to a remote computer over a
communications link. Study the following pseudocode:
NOTE
ASC(ThisChar : CHAR) RETURNS INTEGER
Explain the purpose of sending the value of StringTotal to the remote computer, in addition to
MyString.
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Question 20
Index 0 1 2 3
0 3 15 6 17
1 6 3 1 1
2 17 2 33 3
X Y DataArray[x,y] Count
Question 22
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
……………………………………………………………………………………………………...[3]
What are the three stages of storing data into a file?
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
……………………………………………………………………………………………………...[3]
Create a text file with the name "myData.txt". Enter a word in the file.
Write a program to read the word from the file and output it.
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
……………………………………………………………………………………………………...[4]
Create a text file with the name "store.txt". Write a program to read a word
from the user and store it in this file.
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
……………………………………………………………………………………………………...[4]
Question 23
Write an algorithm using pseudocode to store a total in a text file with the
name "TotalData.txt".
The algorithm asks the user to enter numbers to add to this total. The program
then stores the new total in the same text file.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 24
A company creates two new websites, Site X and Site Y, for selling bicycles.
Various programs are to be written to process the sales data.
These programs will use data about daily sales made from Site X and Site Y
The one-dimensional (1D) array SalesDate[1:28] contains the dates for the
sales made to site X and site Y
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays Sales[] and SalesDate[]
The variables X, Y and Z are used in a program: X stores a whole number, Y stores a decimal
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………….[3]
The function Same(A,B) returns TRUE if the value of A is the same as the value of B when B
Function definition
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………….[6]
Function call
…………………………………………………………………………………………………….[1]
State the difference between defining and calling a function.
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………….[1]
Question 26
The one-dimensional (1D) array TeamName[] contains the names of teams in a sports league.
The two-dimensional (2D) array TeamPoints[] contains the points awarded for each match.
The position of each team’s data in the two arrays is the same. For example, the team stored at
index 10 in TeamName[] and TeamPoints[] is the same.
The variable LeagueSize contains the number of teams in the league. The variable MatchNo
contains the number of matches played. All teams have played the same number of matches.
The arrays and variables have already been set up and the data stored.
Each match can be played at home or away. Points are recorded for the match results of each
team with the following values:
3 – away win
2 – home win
1 – drawn match
0 – lost match.
Write a program that meets the following requirements:
calculates the total points for all matches played for each team
counts the total number of away wins, home wins, drawn matches and lost matches for each
team
outputs for each team:
– name
– total points
– total number of away wins, home wins, drawn matches and lost matches
finds and outputs the name of the team with the highest total points
finds and outputs the name of the team with the lowest total points.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays, variables or constants; you may assume that this has
A program halted unexpectedly with the error message ‘File not found’ whilst trying to read
data from a file. Outline the actions that the program needs to take to prevent this error occurring
[2]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
Question 28
02 Q ← LENGTH(P) ……………………………………………
03 R ← SUBSTRING(P,10,7) ……………………………………………
04 S ← LENGTH(R) ……………………………………………
05 T ← SUBSTRING(R,1,3) ……………………………………………
Write a pseudocode statement to extract the word Computer from P and store it in the variable F. [1]
…………………………………………………………………………………………………………
Question 29
The names of patients are stored in the one-dimensional (1D) array Patient[] of type string. A
separate two-dimensional (2D) array Readings[] stores the latest data recorded about each
patient. The array already contains the readings taken by a nurse for each patient:
temperature measured to one decimal place
pulse rate, a whole number.
Temperature readings should be in the range 31.6 to 37.2 inclusive.
Pulse readings should be in the range 55.0 to 100.0 inclusive.
The hospital number given to the patient is used for the index on both arrays, this is a value between
1 and 1000 inclusive.
When the data for a patient is checked a warning is given if any of the readings are out of range. If
both readings are out of range, then a severe warning is given.
Write a procedure, using pseudocode or program code, that meets the following requirements:
takes the hospital number as a parameter
checks if the number is valid
outputs an error message and exits the procedure if the number is not valid
if the hospital number is valid: output the patient’s name
output ‘Normal readings’ if both the readings are within range
output ‘Warning’ and the name of the reading e.g. ‘Pulse’ if one reading is out of range
output ‘Severe warning’ and the names of the two readings ‘Pulse and temperature’ if
both readings are out of range
exits the procedure.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to initialise the data in the arrays.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………….[15]