0% found this document useful (0 votes)
132 views103 pages

Homework #08 - Questions: For To Next

Uploaded by

Amira Okasha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views103 pages

Homework #08 - Questions: For To Next

Uploaded by

Amira Okasha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 103

Homework #08 – Questions

One Dimensional Array Questions

Question 1

Write an algorithm, using pseudocode and a FOR … TO … NEXT loop structure, to input 1000
numbers into an array. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Rewrite your algorithm using another loop structure. [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]

Membership Details Data Type

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]

Data Structure ………………………………………………………………………………….

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

Describe the purpose of each statement in this algorithm. [3]


FOR I ← 1 TO 300
INPUT Name[I]
NEXT

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

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'

There are four lines of code that contain errors.


State the line number for each error and write the correct code for that line.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
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

The flowchart below represents a program routine. [5]


The array used in the flowchart contains the following data:

Complete the trace table using the data given in the array.

Describe what the algorithm represented by the flowchart is doing. [2]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Convert the flowchart in question 10 to pseudocode [5]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
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

Complete the trace table for the input data: 5, 7, 0, 1, 2, 3, 4

Complete the trace table for the input data: 4, 3, 1, 0, 2, 3, 1

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

An algorithm is written in pseudocode:


Total ← 0
FOR Count ← 1 TO 50
INPUT Num
Total ← Total + Num
NEXT Count
OUTPUT Total

Describe the purpose of the algorithm. [3]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Re-write the algorithm in pseudocode using a different type of loop. [3]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Describe how you could modify the original algorithm shown at the start of question 13, to allow
any number of inputs. [2]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Question 14

The flowchart performs a mathematical process on a number input called TestNum


DIV is used to represent integer division e.g. 7 DIV 3 = 2
Complete the trace table for the input data: 7

Complete the trace table for the input data: 6

State the purpose of the algorithm in the flowchart. [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

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

Input data: 6, 3.5, 4

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

Input data: 58, 40, 67, 85, 12, 13, 75, 82

Give the purpose of the algorithm [1]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

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

Complete the trace table for the input data: 10

[6]

Describe the function being performed by the algorithm. [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

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

Explain why the algorithm will never end. [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

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

This pseudocode represents an algorithm.

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

The contents of the array at the start of the algorithm are:

Complete the trace table for the algorithm using the data given in the array. [5]

Describe the purpose of the algorithm. [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
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.

Describe what happens in this algorithm. [3]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
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

A one-dimensional array dataArray[1:20] needs each element set to zero.

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

The flowchart represents an algorithm.


The algorithm will terminate if 0 is entered at the Op input. [5]
Complete the trace table for the algorithm using this input data:
1, 87, 14, 3, 2, 30, 5, 10, 6, 4, 10, 2, 0, 2, 90, 6

State the purpose of the algorithm. [1]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

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]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Identify another loop structure available in pseudocode. [1]


…………………………………………………………………………………………………………
Question 35

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

Describe a one-dimensional array. Include an example of an array declaration. [3]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Explain how indexing could be used to search for a value stored in a one-dimensional array. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 37

The pseudocode represents an algorithm.


The pre-defined function DIV gives the value of the result of integer division.
For example, Y = 11 DIV 4 gives the value Y = 2

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

This section of program code may be used as a validation check.


1 PRINT "Input a value between 0 and 100 inclusive"
2 INPUT Value
3 WHILE Value < 0 OR Value > 100
4 PRINT "Invalid value, try again"
5 INPUT Value
6 ENDWHILE
7 PRINT "Accepted: ", Value

Give a name for this type of validation check.


……………………………………………………………………………………………………...[1]
Describe what is happening in this validation check.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………..[1]
Complete the trace table for this program code using the test data: 200, 300, –1, 50, 60

[3]
Draw a flowchart to represent this section of program code. [5]
Question 3

Explain what is meant by validation and verification.


Give an example for each one.
Validation
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Example
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Verification
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Example
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………..[6]
Question 4

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 the use of a subroutine in a program. [2]


………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Question 8

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 program checks if the weight of a baby is at least 2 kilograms.


Give, with reasons, two different values of test data that could be used for the baby’s weight.
Each reason must be different.
Value 1
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
Value 2
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
Question 13

Explain the difference between a validation check and a verification check.


………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Describe, using an example, how data could be verified on data entry.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Explain what is meant by the term library routine.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………........
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[3]
Question 14

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

This pseudocode algorithm is used as a validation check.


PRINT "Input a number from 1 to 5000"
REPEAT
INPUT Number
IF Number < 1 OR Number > 5000 THEN
PRINT "Invalid number, please try again"
ENDIF
UNTIL Number >= 1 AND Number <= 5000
PRINT Number, " is within the correct range"

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

Validation check name


………………………………………………………………………………………………………....
Description of use
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 17

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

A software company is working on a project to develop a registration system for a school.


The registration system project has progressed to the design stage.
State three activities that will take place during the design stage of the program development life
cycle.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[3]
Question 21

Functions and procedures are subroutines.


Explain why you should use subroutines when designing a program solution
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Question 22

Identify three different ways of presenting the design of a solution.


………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[3]
Identify the four different types of test data.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[4]
Question 23

Describe the use of decomposition in the design of a solution


………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Question 24

Explain the difference between counting and totalling.


………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Question 25

A food ordering system is an example of a computer system that is made up of sub-systems.


The food ordering system:
 allows the user to enter the details of the food they want to order and to pay for the
order
 displays food available as pictures or as a list.
Complete the structure diagram for the given parts of the food ordering system. [4]
Two-dimensional Array, Functions / Procedures and File handling Questions

Question 01

A student is developing an algorithm to count the number of times a given string,


SearchString, appears in a 2D array. The array, Item, consists of 100 elements organised as 50
rows of 2 columns. SearchString could appear in any row or column. The array is declared in
pseudocode as follows:
DECLARE Item : ARRAY [1:50, 1:2] OF STRING

The structured English description of the algorithm is:


1. SET Count to 0.
2. Examine the first row of the array.
3. IF column 1 element value is equal to SearchString, ADD 1 to Count.
4. IF column 2 element value is equal to SearchString, ADD 1 to Count.
5. REPEAT from step 3 for next row, UNTIL row is last row.
6. OUTPUT a suitable message and Count.
Write pseudocode for the algorithm.
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[7]
Question 2

A function, ProcessMarks(), is required to analyse test marks for a class of students.

 There are 20 students in the class.


 A mark is between 0 and 100.
 The marks for the class are stored in an array, Mark, which has 20 elements.
 The array is passed to the function as a parameter.
 The function will output a message stating the average and highest marks. For
example: "The average mark is 34 and the highest mark is 76"
 The function returns the subscript of the highest mark.
Write pseudocode to implement the ProcessMarks(), function

………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[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]:

The game is to be implemented using the following procedures :


 InitialiseGrid()
 DisplayGrid()
 HideTreasure()
 DigHole(Row,Col)
 StartDig()
We are going to design the algorithm for this program using pseudocode step by step
Step 1
Write pseudocode to declare a 2D array called Grid to represent the squares of the island

………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[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 ……………………

……………………

……………………

PRINT() //New line

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()

 Prompts the player for a location to dig


 Validates the user input
 Calls the DigHole procedure from step 5

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.

Write pseudocode for the procedure Summarise().

…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[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.

Complete the missing pseudocode statement [5]


YearSize ← 249
Flag ← TRUE
WHILE Flag = TRUE
Flag ← FALSE
FOR Student ← 1 TO ………………………………………………..
IF Score[Student] < Score[Student + 1] THEN
Temp1 ← Score[Student]
Temp2 ← Name[Student,1]
Temp3 ← Name[Student,2]
Score[Student] ← Score[Student + 1]
Name[Student,1] ← Name[Student + 1,1]
Name[Student,2] ← Name[Student + 1,2]
Score[Student + 1] ← ………………………………………
Name[Student + 1,1] ← ……………………………………
Name[Student + 1,2] ← …………………………………
Flag ← ………………………………………………..
ENDIF
NEXT Student
ENDWHILE
Question 6

The following pseudocode declares and initialises an array.


DECLARE Code : ARRAY[1:100] OF STRING
DECLARE Index : INTEGER
FOR Index 1 TO 100
Code[Index] ← ""
NEXT Index

The design of the program is changed as follows:


 the array needs to be two dimensional, with 500 rows and 4 columns
 the elements of the array need to be initialised to the string "Empty"

Re-write the pseudocode to implement the new design.


…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 8

The following pseudocode is an example of nested IF statements


IF MyVar = 1 THEN
CALL Proc1()
ELSE
IF MyVar = 2 THEN
CALL Proc2()
ELSE
IF MyVar = 3 THEN
CALL Proc3()
ELSE
OUTPUT "Error"
ENDIF
ENDIF
ENDIF

Use pseudocode to write a CASE statement with the same functionality


…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[6]
Question 9

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

Gina is developing her programming skills in string handling.


She is going to input one string.
The string contains letters and zero or more '*' characters in any positions.
Gina wants to remove all the '*'s and output the letters in their original order.
For example:
• input "com*put**er*", the output is "computer"

• input " hardware", the output is "hardware"

Write an algorithm using pseudocode to perform this task. (Ensure that you use meaningful variable
names)

You will need to use:


 & Concatenates (joins) two strings Example: "Summer" & " " & "Pudding" evaluates to
"Summer Pudding" Note: This operator may also be used to concatenate a character with a
string
 SUBSTRING
 LENGTH

…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[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.

This grid of asterisks (*) is produced by the procedure call:


ShowMultiplicationGrid(3, 4)

Complete the pseudocode for this procedure:


PROCEDURE ShowMultiplicationGrid(Number1 : INTEGER,
Number2: INTEGER)
DECLARE Row , Column : INTEGER
FOR Row ← ……………………………………………………………………
FOR Column ← ……………………………………………………………………
OUTPUT ('*')
NEXT Column
OUTPUT() //NewLine
NEXT Row
ENDPROCEDURE
The procedure CheckAnswerCorrect gives the child three chances to type in the correct
answer.
OUTPUT "Correct. Well done! " if the child typed the correct answer,
OUTPUT "You need to practice more. The correct answer is ", Result
if all three attempts are incorrect.
Write an algorithm using pseudocode for the procedure CheckAnswerCorrect .

…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[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

Explain why a program might need to store data in a file.


………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Question 14

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.

Write a program that meets the following requirements:


 calculates the combined total mark for each student for all their subjects
 calculates the average mark for each student for all their subjects, rounded to the nearest
whole number
 outputs for each student
 name
 combined total mark
 average mark
 grade awarded
 calculates, stores and outputs the number of distinctions, merits, passes and fails for the
whole class.
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 array.
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………….[15]
Question16

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

Part of the validation is implemented by the line:


IF NOT (Dots >= 1 AND Ats = 1 AND Others > 8) THEN

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

A procedure FirstLines() will:

 take the name of a text file as a parameter


 output the first three lines from that file, in the same order as they appear in the file.
Note:
 You may assume the file exists and contains the three lines.
Write pseudocode for the procedure FirstLines().

…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[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

The program flowchart represents an algorithm for FirstTen().

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

returns an integer value (the ASCII value) of ThisChar

Example: ASC('A') returns 65


OUTPUT "Enter string"
INPUT MyString
StringTotal ← 0
FOR i ← 1 TO LENGTH(MyString)
NextNum ← ASC(SUBSTRING(MyString, i))
StringTotal ← StringTotal + NextNum
NEXT i
OUTPUT MyString, StringTotal

Explain the purpose of sending the value of StringTotal to the remote computer, in addition to
MyString.

…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[2]
Question 20

The company maintains a file of product data


The program records the following data for each product:
 • product code
 • product description
 • product retail price
The text file PRODUCTS.TXT stores each data item on a separate line, as shown below:

The program uses the variables shown in the identifier table.

Identifier Data type Description

TEXT FILE Storing the code, description and


PRODUCTS.TXT
retail price for all current products

PCode ARRAY[1:1000] OF STRING Array storing the product codes

ARRAY[1:1000] OF STRING Array storing the product


PDescription
descriptions

ARRAY[1:1000] OF REAL Array storing the product retail


PRetailPrice
prices

INTEGER Array index used by all three


i
arrays
The program reads all the product data held in file PRODUCTS.TXT and write them into the three
1D arrays. Complete the pseudocode below.
OPENFILE "PRODUCTS.TXT " FOR READ
i ← 1
READFILE "PRODUCTS.TXT ", PCode[i]
WHILE LENGTH(PCode[i]) > 0 DO
READFILE "PRODUCTS.TXT ", ………………………………………………………
READFILE "PRODUCTS.TXT ", ………………………………………………………
READFILE "PRODUCTS.TXT ", ………………………………………………………
i ← i + 1
ENDWHILE
CLOSE "PRODUCTS.TXT"
OUTPUT "Product file contents written to arrays"
Question 21

Complete the trace table for the following algorithm [4]


Count ← 0
FOR y ← 0 TO 2
FOR x ← 0 TO 3
IF DataArray[x][y] = 3 THEN
Count ← Count + 1
ENDIF
NEXT x
NEXT y
OUTPUT(Count)

The array DataArray currently stores the data:

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

Why do programs sometimes need to store data in a file?


…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
……………………………………………………………………………………………………...[1]
What are the three stages of reading data from a file?

…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
……………………………………………………………………………………………………...[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

The two-dimensional (2D) array Sales[1:28,1:2] contains the number of sales


made for each site

Data for the first 28 days is shown below.

SalesDate SiteX SiteY


1 03/06/2015 1 0 2
2 04/06/2015 2 1 8
3 05/06/2015 3 3 0
4 06/06/2015 4 0 6
5 07/06/2015 5 4 4
6 08/06/2015 6 4 9
7 09/06/2015 7 5 9
8 10/06/2015 8 11 1
… … … … …
28 01/07/2015 28 14 8

Write a program that meets the following requirements:


 Calculate and output the total number of sales made for each site for the first 28 days.
 For the first seven days only, calculate the number of days that total sales were 10 or over
when you add the sales for site x plus the sales for site y. Output the corresponding date and
the final total number of days

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[]

All inputs and outputs must contain suitable messages.


You do not need to initialise the data in the arrays Sales[] and SalesDate[]
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………….[15]
Question 25

The variables X, Y and Z are used in a program: X stores a whole number, Y stores a decimal

number and Z stores a flag that can be set to TRUE or FALSE

Write pseudocode statements to declare the variables X, Y and Z

………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………….[3]
The function Same(A,B) returns TRUE if the value of A is the same as the value of B when B

is rounded to the nearest whole number and FALSE otherwise.

Write pseudocode statements to:


 define the function
 call the function with X and Y and store the return value in Z

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

already been done.


All inputs and outputs must contain suitable messages.
You do not need to initialise the data in the arrays TeamName[] and TeamPoints[] or the

variables LeagueSize and MatchNo


…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………………
………………………………………………………………………………………………………....
…………………………………………………………………………………………………….[15]
Question 27

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

A function LENGTH(X) finds the length of a string X and a function SUBSTRING(X,Y,Z)


finds a substring of X starting at position Y and Z characters long. The first character in the string
is position 1. Show the value of the variable after each pseudocode statement has been executed.
[5]
01 P ← "Computer Science" ……………………………………………

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]

You might also like