You are on page 1of 8

PRM 2020

Cambridge IGCSE / 0
Level Computer Science
� Cambridge Assessment
� International Education


Cambridge IGCSE

�,--
COMPUTER SCIENCE 0478122
Pape:r 2 Problam-sOlvlng and Progmmming May/June 2020
PRE-RELEASE MATERIAL

•- No additional materi.alS are needed.

This material $hould be given to the relevant teachers and candidates as: soon as it has been

·-
u-
n- received at the centre.
,!!!! ----------------------------------
:• INSTRUCTIONS
You shOuld use this ma1erial ln pr�ratiOn ror the examination.
i- : You shOuld attempt the practical progra mming taskS us.ing your Chosen h;gh-4&v()J, procedural
programming language.

This document has 2 pages_ Blank pages are indicated.

OC(CJ) 1&492713
CIUCL£S2020 [Turn over
Your preparation for the examinati on should include attempting the following practical tasks by writing
and to.sting a program or programs.
A car park payment system allows customers to seJect the number of hours to leave their car in the car
park. The customer will get a discount if they enter their frequent parking number correctty. The system
calculates and displays the amount the customer must pay. The price of parking. the number of hours
the customer can enter, and any discount depend upon the day of the week and the arrival time. The
number of hours entered is a whole number. The price per hour is calculated using the price in force at
the arrival time. No parkin g is allowed between Midnight and 08:00.
Arrlva.l tlme
Day of the week From 08:00 to 15:59 From 16:00 to Midnight
Max stay in hours Price per hour Hours Price
Sunday 8 2.00 Up to M idnight 2.00
Monday 2 10:0 0 U p to Mldnigh< 2.00
Tuesday 2 10,00 Up to Midnight 2.00
Wednesday 2 10.-00 Up to Midnight 2.00
Thursday 2 10.-00 Up to Mldnlgh< 2.00
Friday
Saturday •
2 10.-0 0
3.00
U p t o Midnight
Up to Midnight
2.00
2.00

A frequent parking number can be entered for disco unted parking. This number consists of 4 digits and
a check digit that is calculated using a moduk> 11 check digit calculation. A discount of 50% is available
for arrival times from 16:00 to Midnight; the discount is 10% at all other arrival times.
Write and lest a program or programs to simulate the car park payment system.
Your program or programs must include appropriate prompts for the entry of data; data must be
validated on entry.
Error messages and other output need to be set out clear1y and understandably.
All variables. con stants and other identifiers must have meaningful names.
You will need to complete these three tasks. Each task must be fully tested.
Task 1 -Calculating lhe price to park.
A customer inputs the day, the hour of arrival excluding minutes (for example 15:45 would be 15), the
number of hours to leave their car, and a frequent parking number if available. If the frequent parking
number has an incorrect check digit, then no disoount can be applied. The price to park, based on
the day, the hour of arrival, the number of hours of parking required and any discount available, is
calculated and displayed.
Task 2 - Keeping a total of the payments.
Extend Task 1 to keep a daily total of payments made for parking. The daily total is zeroed at the start of
the day. For the simulation, each customer inputs the amount paid, this must be greater than Of equal to
the amount displayed. There is no change given so the amount input may exceed the amount displayed .
Eadl customer payment is added to the daily total. and this total is displayed at the end of the day.
Task 3 -Making payments fairer.
Customers have complained that sometimes they are being charged too much if they arrive before
16:00 and depart after 16:00. Extend Task 1 to calculate lhe price before 16:00, then add lhe evening
charge. For example. a customer arriving at 14:45 on a Sunday and parking for five hours was
previously charged 10.00 and would now be charged 6.00

C UClES 2020 047&'22/PRE/M.!J/20


DECLARE day[) + {''Sunday u, "Monday"', '"Tuesday"', "Wednesday"', "Thursday",
"Friday", "Saturday"}
DECLARE duracion[J + {B, 2, 2, 2, 2, 2, 4}
0 DECLARE price[} + {2, 10, 10, 10, 10, 10, 3}
DECLARE userDay, userArrivalHour, userDepartHour, parkingDuration, coun�,
freqParkingNur.i: INTEGER
DECLARE digit, num, sum, parkingPrice, pricePaid, dailyiotai, discount DOUBLE
DECLARE userChoice : CHAR
REPEAT
I/Talt.in9 .i..nput of day number froai u::e..r until vali d . ed
. day nw:ibe% {1 - 7) i:: enter
REPEAT
PRINT "En�er day number."
PRINT • l - Sunday I 2 - Monday I 3 - Tuesday I 4 - Wednesday I
S - Thursday l € - Friday I 7 - Saturday "
INPUT userDay
ONTIL userDay >= 1 AND userOay <= 7
// TaJti.nt" input of u.::.e.r':: arrival. tilDe and e=u.r.ia.9 it i:: in correct fonraat and .re.ntJe
REPEAT
PRINT "Enter time of arrival I No Parking fron Midnight (0090) TO
07: 591>11 {0759) ")
INPUT userArrivalHour
ONTIL userArrivalHour >= 8 AHO userArrivalHour <= 23
//Takin<J iJlput of du.rati04 aeeoxd.in'J to the day n-wllbe.x choo�en
REPEAT
PRINT "Encer durat.ion of parking : "

0
PRINT "Sunday : Max 8 Hrs, Saturday : He.x 3 H�s, Other days 11ax 2 Hrs "
INPUT parkingDuration
userDeparcHour +- userfl-rrivalHour + parJ.:ingDuration
ONTIL parkingDuration <= duration[userDay] AND userDepartHour < 24

parkingPrice + 2
IF userP.rrivalHour < 16 THEN
parkingPrice + price[userDay) � parkingDuration
ENDIF
,,

PRINT "Day : " , day(userDay)


PRINT ":ime of arr:.val " , userArrivalHour
PRINT "Tirr:e of departu�,e userDepartHour
PRINT "Price without d.:.scount .. , pad:ingPrice
PRINT "Enter l if F,:.N number avai:.b-ale "}
INPUT finChoice
IF finChoice: = 1 THEN

o[
//Inputti.ny fre<JU-e,Dt Paddn<J Nw:.ber::: {M:;:umi.n9 it can bepn from. 00000 to 99999
REPEAT
PRINT "Ente= Frequent Identi:":cat:.on Nu!flber ...
INPOT freqParkingNum
UNTIL freq?arkingNum >= O AND freqParkingNum <= 99999
//3eparae.t!:. eaeh digit and caleula�in3 ch��k digit
num + freqParl:ingNum
count +- l
REPEAT
digit + num MOD !O
sum+ sum + digit 1 count
num � INT (num / 10)
count +- count + 1
UNTIL digic <= 0

IF sum MOD 11 = 0 THEN


IF userArriva!Hour >= 16 THEN
discount + 0.5
ELSE
discount + 0.1
0 ENDIF
parkingPrice + parkingPrice k (1 - discount)
PRINT "Pr:.ce ·,1ith Discount : " , parJdngPrice
ELSE
PRINT "Sorry, there was no discount"
ENDIF
ENDIF
Task2
REPEAT
PRINT "P.mount Due is ,. & par}:ingPrice & " Please enter the amount
INPUT price?aid
UNTIL price?aid >= parkingPrice

[ PRINT
0[ dailyTocal + daily!otal + :pric.ePaid
"Press any key to enab:e another use= Cata (Other than space key) I I
� i:� Space key to end th,e, day "
userChoice
UNTIL userChoice
PRINT "Sa::e-s for t.od.ay are : ._,, dailyiotal

// Above Loop started in Task 1 whereas terminated in Task 2 when day ended.
//(T2 is extension of Tl)

Task3

// Instead of code in RED box 1n Task 1 following code would be written

parkingPrice + 2
IF userArrivalHour < 16 THEN
IF userDepartHour < 16 THEN
parkingPrice +- price[userDay] k parkingDuration
ELSE
parking?rice +- price(userDay] k (pa.rkingDura�ion - (userDepartHour - 16))
9arking?rice + parkingPrice + 2
ENDIF
ENDIF
' Declaring variables.

Taking input of day as index of


array until it is valid

Taking input of arrival hour as


until ij is valid 8am to midnight.

Validating duration and then


using it in cost calculation.

Validating frequent identification


number to be 5 digit

Preparing sum of all digits in


F.I.N

Ched(ing whether and what


type of discount applicable.

Taking input of cost from


user.

Adding the cost to the


daity earning.

Pressing SPACE key marlls end


of th e day and displays the total
for the day. (Company's Control)

You might also like