COMPUTER SCIENCE 0478/22 COMPUTER SCIENCE 2210/22
Paper 2 Problem-solving and Programming
PRE-RELEASE MATERIAL SOLVED
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 for delivery. A price for the order will
be calculated.
Write and test a program for the manager
Your 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.
.M
us
ht
aq
TASK 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 easy identification
o C-cement
o G-gravel
o S-sand
Sand and gravel must weigh over 49.0 and under 50.1 kilograms
Cement must weigh over 24.9 and under 25.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).
M
TASK 2- check a customer’s 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 weigh 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 customer’s order
Extend TASK 2 to calculate a price for an order. Prices for the sacks are as follows:
Regular price for each sack
o Cement,$3
o Gravel,$2
o Sand,$2
Discount price for a special pack containing 1 sack of cement,2 sacks of sand and 2 sacks
of gravel,$10
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.
Task 1 solved
MinCem=24.9
MaxCem=25.1
minGS=49.0
maxGS=50.1
Input content
Do while
content < >C
or content < >G or
content < >S
Print “invalid content, please enter a C, G or S”
Input content
Loop
ht
aq
If content=c then
Repeat
Input weight
If weight <=minCem then
Print “sack of cement is underweight, rejected”
Else if weight>=maxCem then
Print “sack of cement is overweight, rejected”
Else
Print weight, content
End if
Until weight >minCement and weight < maxCement
End if
M
.M
us
If content=G or content = S then
Repeat
Input weight
If weight <=minGS then
Print “sack is underweight, rejected”
Else if weight>=maxGS then
Print “sack is overweight, rejected”
Else
Print weight, content
Until weight >minGS and weight < maxGS
Task 2
invC=0, invG=0, invS=0, rej=0
AcC=0, AcG=0, AcS=0, total=0
TCW=0, TGW=0, TSW=0, TW=0
Print “enter your order”
Input nc,ng,ns
Do
aq
Input content
If content = "c" Then
Do
Input weight
If weight > 24.1 And weight < 25.1 Then
AcC = AcC + 1
TCW = TCW + weight
Else
invC = invC + 1
ht
End If
Loop Until weight > 24.9 And weight < 25.1
.M
us
ElseIf content = "g" Then
Do
Input weight
If weight > 49.9 And weight < 50.1 Then
AcG = AcG + 1
TGW = TGW + weight
Else
invG = invG + 1
M
End If
Loop Until weight > 49.9 And weight < 50.1
ElseIf content = "s" Then
Do
Input weight
If weight > 49.1 And weight < 50.1 Then
AcS = AcS + 1
TSW = TSW + weight
Else
invS = invS + 1
End If
Loop Until weight > 49.1 And weight < 50.1
End If
Loop Until nc = AcC And ng = AcG And ns = AcS
rej = invC + invG + invS
TW = TCW + TGW + TSW
print("total accepted sacks of each content=" & AcC & AcG & AcS)
print("total weight of the order " & TW)
print("the regected number of packs are =" & rej)
Solution task 3
Print “enter order of cement,gravel or sand”
Input cOrder,gOrder,sOrder
min = 1000
x=c
y = Int(gOrder / 2)
'comment special pack 1 cement,2 gravel,2 sand
z = Int(sOrder / 2)
'minimum will be the special sack
RemCement = c - min
RemGravel = g - min * 2
RemSand = s - min * 2
'comment:find remaining sack
ht
aq
If x < min Then min = x
If y < min Then min = y
If z < min Then min = z
.M
us
'Remaining sacks price calculation
RemPrice = RemCement * 3 + RemGravel * 2 + RemSand * 2
SpeSackPrice = min * 1 * 3 + min * 2 * 2 + min * 2 * 2
'special packs price calculation
DiscSpeSack = SpeSackPrice -min
DisOrderPrice = RemPrice + DiscSpeSack
‘order with discount on special packs
OrderPrice=RemPrice+SpeSackPrice
‘order without discount
MoneySaved=OrderPrice-DisOrderPrice
‘total money saved after discount
M
Print "The number of special packs = ", min
Print "the price of special packs = ", SpeSackPrice
Print "the diccounted price of special packs = ", DiscSpeSack
Print "the remaining cement,gravel and sand =", RemCement, RemGravel, RemSand
Print "price of the order = ", OrderPrice
Print”total money saved=”,MoneySaved
Task 3 (alternate method)
Dim ordC, ordG, ordS, spc, spg, sps, c, g, s As Integer
Dim spePrice, disSpePrice, ordprice, amtSvd, DisOrdPrice, remPrice As
Integer
ht
aq
Console.WriteLine("enter order one by one")
ordC = Console.ReadLine
ordG = Console.ReadLine
ordS = Console.ReadLine
Do While ordC < 0 Or ordG < 0 Or ordS < 0
Console.WriteLine("incorrect order")
Console.WriteLine("enter order one by one")
ordC = Console.ReadLine
ordG = Console.ReadLine
ordS = Console.ReadLine
Loop
c = ordC
g = ordG
s = ordS
Do While ordC >= 1 And ordG >= 2 And ordS >= 2
spc = spc + 1
ordC = ordC - 1
spg = spg + 2
ordG = ordG - 2
sps = sps + 2
ordS = ordS - 2
Loop
M
.M
us
spePrice = spc * 3 + spg * 2 + sps * 2
disSpePrice = spc * 10
remPrice = ordC * 3 + ordG * 2 + ordS * 2
DisOrdPrice = remPrice + disSpePrice
ordprice = c * 3 + g * 2 + s * 2
amtSvd = ordprice - DisOrdPrice
Console.WriteLine("special cement sacks " & spc & " remainig cement
" & ordC)
Console.WriteLine("special gravel sacks " & spg & " remainig gravel
" & ordG)
Console.WriteLine("special sand sacks " & sps & " remainig sand " &
ordS)
Console.WriteLine("price of special packs is " & spePrice)
Console.WriteLine(" discounted price of special packs " &
disSpePrice)
Console.WriteLine("Remaining order prince =" & remPrice)
Console.WriteLine("discounted order prince =" & DisOrdPrice)
Console.WriteLine("normal order prince =" & ordprice)
Console.WriteLine("amount saved =" & amtSvd)
Console.ReadKey()
Task 3 (pseudocode)
Dim ordC, ordG, ordS, spc, spg, sps, c, g, s As Integer
Dim spePrice, disSpePrice, ordprice, amtSvd, DisOrdPrice, remPrice As
Integer
aq
Print “enter order one by one"
Input ordC,ordG,ordS
Do While ordC < 0 Or ordG < 0 Or ordS < 0
Print("incorrect order")
Print("enter order one by one")
Input ordC,ordG,ordS
Loop
c = ordC
g = ordG
s = ordS
Do While ordC >= 1 And ordG >= 2 And ordS >= 2
spc = spc + 1
ordC = ordC - 1
spg = spg + 2
ordG = ordG - 2
sps = sps + 2
ordS = ordS - 2
Loop
M
.M
us
ht
spePrice = spc * 3 + spg * 2 + sps * 2
disSpePrice = spc * 10
remPrice = ordC * 3 + ordG * 2 + ordS * 2
DisOrdPrice = remPrice + disSpePrice
ordprice = c * 3 + g * 2 + s * 2
amtSvd = ordprice - DisOrdPrice
Print("special cement sacks " & spc & " remainig cement " & ordC)
Print("special gravel sacks " & spg & " remainig gravel " & ordG)
Print("special sand sacks " & sps & " remainig sand " & ordS)
Print("price of special packs is " & spePrice)
Print(" discounted price of special packs " & disSpePrice)
Print("Remaining order prince =" & remPrice)
Print("discounted order prince =" & DisOrdPrice)
Print("normal order prince =" & ordprice)
Print("amount saved =" & amtSvd)
Console.ReadKey()
ht
.M
us
M
aq
© Copyright 2025 Paperzz