Beruflich Dokumente
Kultur Dokumente
O LEVEL
COMPUTER
SCIENCE
2210
PRACTICE PAPER OF
PRE-RELEASED MATERIAL
MAY/ JUNE 2016
In preparation for the examination candidates should attempt the following practical tasks by writing and
testing a program(s).
The manager of a building materials delivery service needs a program to check the contents and weight
of sacks to ensure that correct orders are made up of delivery. A price for the order will be calculated.
Write and test a program for the manager.
You program must include appropriate prompts for the entry of data.
Error messages and other output need to be set out clearly.
All variables, constants and other identifiers must have meaningful names.
You will need to complete these three tasks. Each task must be fully tested.
TASKS 1 Check the contents and weight of a single sack.
Each sack must obey the following rules to be accepted:
Contain cement, gravel or sand with a letter on the side for the easy identification.
C cement
G gravel
S sand
sand or gravel must weigh over 49.9 and under 50.1 kilograms
cement must weigh over 24.9 and under 50.1 kilograms
Input and store the weight and contents for one sack. The contents must be checked and an incorrect
sack rejected. The weight must be validated on entry and an overweight or underweight sack rejected.
Output the contents and weight of an accepted sack. If a sack is rejected, output the reason(s).
TASK 2 Check a customers order for delivery.
Input and store the number of sacks of each type required for the order. Use TASK 1 to check the
contents and weight of each sack. Ensure that the delivery contains the correct number and type of sacks
for the order.
Output the total weight of the order.
Output the number of sacks rejected from the order.
TASK 3 Calculate the price for a customers order.
Extend TASK 2 to calculate a price for an order. Price for the sacks are as follows:
Calculate and output the regular price for the order. Check how many special packs are in the order. If a
discount price applies then output the new price for the order and the amount saved.
Page
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
SOLUTION IN PSEUDOCODE:
TASK 1 Check the contents and weight of a single sack
Initialization of Variables
SET SackType
SET Weight 0
ET LowerLi it 0
ET UpperLi it 0
Sand or Gravel must weigh over 49.9 and under 50.1 kilograms
Cement must weigh over 24.9 and under 25.1 kilograms
Repeat
Print "Please Enter the sack weight:"
Input Weight
If SackType "C" and Weight <= 24.9 Then
Print "Sacks weight is rejected due to underweight"
ElseIf Weight >= 25.1 Then
Page
EndIf
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
LowerLimit 24.9
UpperLimit 25.1
ElseIf SackType "G" Or SackType "S" AND Weight <=49.9 Then
Print "acks weight is rejected due to underweight"
ElseIf Weight >= 50.1 Then
Print "Sacks weight is rejected due to overweight"
End If
LowerLimit 49.9
UpperLimit 50.1
End If
Until Weight > LowerLimit AND Weight < UpperLimit
Print "Content of Sack or Sack Types " , SackType
Page
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
Initialization of Variables
Counter 0, SackType , Weight 0, TotalNoOfSacks 0, SacksOfCement 0,
SacksOfGravel, 0, SacksOfSand 0, RejectedSackType 0, AcceptedSackType 0
Page
If (SackType <> "C" AND SackType <> "G" And SackType <> "S") Then
Print Sack type rejected"
RejectedSackType RejectedSackType + 1
End If
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
If SackType C Then
CementCount CementCount + 1
If CementCount > SacksOfCement Then
Print "Sacks of Cement exceeding the limit"
End If
ElseIf SackType "G" Then
GravelCount GravelCount + 1
If GravelCount > SacksOfGravel Then
Print "Sacks of Gravel exceeding the limit"
End If
ElseIf SackType "S" Then
SandCount SandCount + 1
If SandCount > SacksOfSand Then
Print "Sacks of Sand exceeding the limit"
End If
End If
Until (SackType "C" And CementCount <= SacksOfCement) Or (SackType "G" And GravelCount <=
SacksOfGravel) Or (SackType "S" And SandCount <= SacksOfSand)
Page
LowerLimit 24.9
UpperLimit 25.1
End If
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
ElseIf SackType "G" Or SackType "S" AND Weight <= 49.9 Then
Print "Sack rejected due to underweight"
RejectedSackType RejectedSackType + 1
ElseIf Weight >= 50.1 Then
Print "Sack rejected due to overweight"
RejectedSackType RejectedSackType + 1
Else
TotalWeight TotalWeight + Weight
End If
LowerLimit 49.9
UpperLimit 50.1
End If
Until (Weight > LowerLimit) AND (Weight < UpperLimit)
AcceptedSackType AcceptedSackType + 1
Until AcceptedSackType >= TotalNoOfSacks
Page
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
SET SackType
: Weight 0 : TotalNoOfSack 0 :Counter 0: SacksOfCement 0:
SET SacksOfGravel 0: SacksOfSand 0 :PriceOfCement 3 : PriceOfGravel 2 : PriceOfSand 2
Repeat
Print "Enter No. of sacks of Cement: "
Input SacksOfCement
Print "Enter No. of sacks of Gravel: "
Input SacksOfGravel
Print "Enter No. of sacks of Sand: "
Input SacksOfSand
TotalNoOfSacks acksOfCement + SacksOfGravel + SacksOfSand
If TotalNoOfSacks <= 0 Then
Print Invalid No of Sacks
End If
Until TotalNoOfSacks > 0
Page
Repeat
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
Page
ElseIf SackType "G" Or SackType "S" AND Weight <= 49.9 Then
Print Sack Type is rejected due to underweight
RejectedSackType RejectedSackType + 1
LowerLimit 24.9
UpperLimit 25.1
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
Repeat
If SacksOfCement >= 1 And SacksOfGravel >= 2 And SacksOfSand >= 2 Then
SpecialPack SpecialPack + 1
SacksOfCement SacksOfCement - 1
SacksOfGravel SacksOfGravel - 2
SacksOfSand SacksOfSand - 2
End If
Until SacksOfCement < 1 Or SacksOdGravel < 2 Or SacksOfSand < 2
Print "Price for Total Orders ", TotalPrice , "$"
Page
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
Page
10
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
FOR I <- 1 to 3
PRINT How many , sack[i], sacks?
INPUT sackNumber
FOR j <- 1 to sackNumber
PRINT Enter weight of sack# , j, :
INPUT Weight
CASE sackLetter[i] OF
C :
IF (Weight > cLower) AND (Weight <Upper)
THEN PRINT TotalWeight <- TotalWeight + Weight
ELSE rejected < rejected + 1
ENDIF
G , S :
IF (Weight > gsLower) AND (Weight gsUpper)
THEN TotalWeight <- + Weight
ELSE rejected <- rejected +1
ENDIF
OTHERWISE: PRINT Error: sack does t exist
ENDCASE
NEXT j
NEXT i
Page
11
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
Calculate and output the regular price for the order. Check how many special packs are in the order. If a
discount price applies then output the new price for the order and the amount saved.
Page
G , S :
IF (Weight > gsLower) AND (Weight < gsUpper)
THEN
TotalWeight < TotalWeight + Weight
TotalPrice <- TotalPrice +gsPrice
12
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
13
Page
PRINT
PRINT
PRINT
PRINT
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
1. (a) All variables, constants and other identifiers should have meaningful names.
(i) Variables/ Identifiers/ fields are used to store data that belongs to different data
types.
Write three suitable declarations of fields, its data type and use of each field in TASK 1
and TASK 3
#
Fields
Data types
Use
1
2
3
[3]
(ii) Constants are used in TASK 2 and TAKS 3.
Write suitable declarations for two of these.
State what you used each one for.
Constant 1......................................................................................................
Use...................................................................................................................
........................................................................................................................
Constant 2.........................................................................................................
Use...................................................................................................................
.....................................................................................................................[4]
(b) All variables, constants and other identifiers should have meaningful names.
(i) Declare the array to store the Contents (cement, gravel and sand).
.....................................................................................................................[1]
(ii) Declare the array to store the Contents weights.
..................................................................................................................... [1]
dimensional arrays.
Page
of Cement and 50 Sacks of Gravel. Both types of sacks are being recorded in one
14
(iii) The manager of building material delivery service has received order for 100 sacks
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
........................................................................................................................
..................................................... ...............................................................[1]
(iv) Comment on the efficiency of your design for TASK 3.
........................................................................................................................
........................................................................................................................
Page
15
..................................................... ...............................................................[1]
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
...............................................................................................................................
............................ ........................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
Page
................................................................................................................................[5]
16
....................................................................................................................................
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
................................................................................................................................[5]
Page
....................................................................................................................................
17
....................................................................................................................................
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
(e) Write a statement in pseudocode that calculates total price of all sacks in TASK 3.
.............................................................................................................................. ......
....................................................................................................................................
[1]
....................................................................................................................................
(f) (i) Show two different sets of building material data that you could use to check the
validation used in Task 2. Explain why you chose each data set.
Set 1.............................................................................................................................
Reason for choice.........................................................................................................
....................................................................................................................................
....................................................................................................................................
Set 2.............................................................................................................................
Reason for choice.........................................................................................................
....................................................................................................................................
[4]
.... ................................................................................................................................
(ii) Describe suitable validation rules for Task 1.
....................................................................................................................................
...................................................................................................................................
[1]
......................................................................... ...........................................................
(iii) How can you show rejected number of sack types if weight doesnt match the lower
and upper weight criteria in TASK 3, using pseudo code or flowchart.
....................................................................................................................................
......................................................................... ...........................................................
....................................................................................................................................
......................................................................... ...........................................................
Page
.................................................................................................................................[2]
18
....................................................................................................................................
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
input up to 20 numbers
stop if the sum of the input numbers exceeds 50
output the final sum
10 count = 0
20 REPEAT
30 INPUT n
40 n + sum = sum
50 IF sum = 50 THEN count = 20
60 count = count + 1
70 UNTIL count = 20
80 OUTPUT n
There are five errors in this algorithm.
Locate these errors and suggest a correction.
Error 1..........................................................................................................................
....................................................................................................................................
Correction 1..................................................................................................................
....................................................................................................................................
Error 2..........................................................................................................................
....................................................................................................................................
Correction 2..................................................................................................................
....................................................................................................................................
Error 3..........................................................................................................................
....................................................................................................................................
Correction 3..................................................................................................................
Page
Error 4..........................................................................................................................
19
[6]
....................................................................................................................................
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
....................................................................................................................................
Correction 4..................................................................................................................
....................................................................................................................................
Error 5..........................................................................................................................
....................................................................................................................................
Correction 5..................................................................................................................
Page
20
[5]
...................................................................................................................................
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
count = 1
repeat
input day, month, year
count = count + 1
until count = 1000
Describe why the loop only inputs 999 dates instead of 1000.
.....................................................................................................................
.....................................................................................................................
.................................................................................................................. [1]
(ii)
What needs to be changed or added to the above code to make sure 1000
dates are input?
.....................................................................................................................
.....................................................................................................................
.................................................................................................................. [1]
(b) Errors in code can be found using test data.
Name three different types of test data. Using month from the pseudocode above,
give an example of each type of test data.
test data type 1.....
example .......
....
test data type 2.....
example .......
......
test data type 3.....
Page
... [6]
21
example .......
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
4. (i) Weight of a sack of a particular content such as Cement, Gravel and Sand is being
recorded using weighing machine. The sacks of Cement and Gravel must weigh under
50.1 kilograms and over 49.9 kilograms. The weigh over 50.1 is rejected and weigh of
sacks below 49.9 kilograms are also rejected.
Give an example of each type of test data for this routine.
Normal..............................................................................................................
Extreme.........................................................................................................
Abnormal ....................................................................................................... [3]
(ii) Identify two different conditional statements that you can use when writing
pseudocode.
1.......................................................................................................................
Page
22
2................................................................................................................... [2]
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
5. The following flowchart inputs ten temperatures and outputs the average (mean)
Page
23
temperature and the number of temperatures which were negative (i.e. < 0).
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
(a) Complete the trace table for this flowchart using the following test data:
5, 11, 16, -4, -10, 8, 10, -3, 17, 10
[4]
(b) What values are outputs from the flowchart using the above test data?
Page
24
.[1]
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
Page
25
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
Complete the following set of instructions to draw the shape in the direction shown by
the arrows.
Page
26
[4]
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
(b) The following set of instructions can be used to control a robot which moves heavy
boxes.
The following set of instructions moves the robot forward 20 steps, turns the robot 90
anti-clockwise and moves the arms up 40cm.
.
.
.[1]
Forward 20
Left 90
Up 40
Page
27
Write three more instrutions so that the robot will return to its original state.
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
7. Four programming concepts and four examples of programming code are shown below.
Draw a line to link each programming concept to the correct example of programming
code.
(a) Write an algorithm, using pseudocode and a FOR TO NEXT loop structure, to
input Wight of 500 students into an array.
.
.
.
.
.
Page
28
.[2]
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
.
.
.
.
.
.
.
.
Page
29
.[4]
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
8. A customer wants to compare prices of 1000 items sold in two supermarkets (price1 and
price2).
Write an algorithm, using pseudocode or a flowchart, which:
inputs the two prices for all 1000 items
outputs how many items were more expensive in supermarket 1
outputs how many items were more expensive in supermarket 2
outputs the largest price difference.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
Page
..[5]
30
..
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
9. A shop keeps its stock file on a computer system. Part of the file is shown in the diagram
below:
2. ..
..[2]
(c) State the data type that should be used for the WEIGHT (KG) data.
...............................................................................................................................................[1]
(d) State one advantage of using fixed-length records for storing the data.
...............................................................................................................................................[1]
(COLOUR NOT B) AND (WEIGHT (KG) < 2.0)
......................................................................................................................................................[2]
Page
31
(e) Which STOCK NO data will be listed if the following search condition is input?
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
(f) Write down a search condition that will search for all the items with less than 16 in
stock and the price is more than $100.
.................................................................................................................................................... [2]
(g) State which field should be used to link this stock file to a supplier file. Give a reason
for your choice of field.
Field..................................................................................................................................................
Reason.............................................................................................................................................
......................................................................................................................................................[2]
10. A database, PROPERTY, was set up to show the prices of properties for sale and the
features of each property. Part of the database is shown below.
.....................................................................................................................[1]
(b) State which field you would choose for the primary key.
... .....................................................................................................................
Give a reason for choosing this field.
.......................................... ..............................................................................
.....................................................................................................................[ 2]
Number of Bedrooms.......................................................................................
Page
Garage..........................................................................................................
32
(c) State the data type you would choose for each of the following fields.
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887
Price in $ .......................................................................................................[3]
(d) The query-by-example grid below selects all houses with more than 1 bathroom and
more than 2 bedrooms.
........................................................................................................................
..................................................................................................................... [2]
Page
33
(e) Complete the query-by-example grid below to select and show the brochure number,
property type and price of all properties with a garage below $200,000.
Website: sirtanviriqbalkhan.tk
Facebook: www.facebook.com/tanvirik
Email: tanviriqbalkhan@gmail.com
PHONE: +923212490887