A program is being developed to implement a customer loyalty scheme for a coffee shop. The programmer has decided that the following data items need to be stored for each customer: Data item Description customer ID a unique six-digit string loyalty points an integer value that depends on how often the customer visits the coffee shop last visit date the date the customer last visited the coffee shop The programmer has defined a program module: Module Description UpdateVisit() • called with two parameters: 1. loyalty points of type INTEGER 2. last visit date of type DATE • change the loyalty points: o increase by four if the last visit date and the current date are in the same month o otherwise increase by one • change the last visit date to the current date • the changed values must be available to the code that follows the call to UpdateVisit()
- (a)(i)Write pseudocode for module UpdateVisit() Assume the customer has made at least one previous visit.[5]
- (a)(ii)The programmer decides to amend the UpdateVisit() module so that loyalty points are further increased if the customer visits the coffee shop the same day of the week as their last visit. Write the pseudocode for this condition.[1]
- (b)(i)A text file Loyalty.txt will be used to store the data items for the loyalty scheme. The text file Loyalty.txt contains only one line of data for each customer. Each data item is separated by a comma: <CustomerID>,<LoyaltyPointsString>,<LastVisitDateString> LastVisitDateString is always eight characters in length in the format: DDMMYYYY. An example of how a line of data will be stored in the text file Loyalty.txt is: "100123,132,05032025" This example shows that the customer with an ID of 100123 had 132 loyalty points following their last visit to the coffee shop on 05/03/2025. If a customer visits the coffee shop on a Monday, the value of their loyalty points is increased by 10. The programmer has defined two more program modules: Module Description FindCustomer() • called with a parameter of type STRING that represents a (is already written) customer ID • returns the line of data read from the text file Loyalty.txt containing the data items for that customer MondayCheck() • called with a parameter of type STRING that represents the customer ID of a customer • calls FindCustomer() • extracts the loyalty points from the string returned by FindCustomer() • increases the loyalty points for the current customer by 10 if the day visited is a Monday • returns an integer value representing the loyalty points Write pseudocode for module MondayCheck() The module FindCustomer() must be used and assume it returns a valid string for the current customer.[8]
- (b)(ii)A date is stored in LastVisitDateString in the format: DDMMYYYY DD is a 2-digit string MM is a 2-digit string YYYY is a 4-digit string. For example, the date 03/09/2024 is stored as "03092024" An algorithm is needed to convert the string stored in LastVisitDateString to data type DATE which is then stored in the variable LastVisitDate. Complete the pseudocode for this algorithm: Assume that LastVisitDateString has been declared and contains valid data. DECLARE DayInt, MonthInt, YearInt : INTEGER DECLARE LastVisitDate : DATE[4]
Mark scheme
Marking points from the official mark scheme (May/June 2025). The mark or mark type is shown in brackets.
- [5] Example solution: PROCEDURE UpdateVisit(BYREF LastVisitDate : DATE, BYREF LoyaltyPoints : INTEGER) IF MONTH(TODAY()) = MONTH(LastVisitDate) THEN LoyaltyPoints <- LoyaltyPoints + 4 ELSE LoyaltyPoints <- LoyaltyPoints + 1 ENDIF LastVisitDate <- TODAY() ENDPROCEDURE
- MP1 Procedure heading and ending and two parameters of correct type
- MP2 ... both passed BYREF
- MP3 Use of TODAY () function to obtain current date
- MP4 Use MONTH function (×2) and one parameter is the header parameter and 2nd parameter is TODAY () / assigned variable
- MP5 If visit is same month, increase LoyaltyPoints by 4 otherwise increase by 1
- MP6 LastVisitDate set to TODAY () / ‘current date' variable (assigned or unassigned)
- Max 5
- [1] DAYINDEX(LastVisitDate) = DAYINDEX(TODAY())
- [8] Example solution: FUNCTION MondayCheck(CustomerID : STRING) RETURNS INTEGER DECLARE LoyaltyPoints : INTEGER DECLARE LoyaltyPointsString : STRING DECLARE Line : STRING Line <- FindCustomer(CustomerID) LoyaltyPointsString <- MID(Line, 8, LENGTH(Line) - 16)) LoyaltyPoints <- STR_TO_NUM(LoyaltyPointsString) IF DAYINDEX(TODAY()) = 2 THEN LoyaltyPoints <- LoyaltyPoints + 10 ENDIF RETURN LoyaltyPoints ENDFUNCTION
- MP1 Value is returned from FindCustomer(CustomerID) and stored
- MP2 Function MID used
- MP3 Attempt to extract LoyaltyPoints from the string returned by FindCustomer()
- MP4 Correct extraction of LoyaltyPoints from the string returned by FindCustomer()
- MP5 Conversion of LoyaltyPoints extracted to an integer
- MP6 Check - is today's date a Monday using TODAY()
- MP7 ... increase LoyaltyPoints by 10
- MP8 Return LoyaltyPoints
- [4] Example solution: DayInt <- STR_TO_NUM(LEFT(LastVisitDateString, 2)) MonthInt <- STR_TO_NUM(MID(LastVisitDateString, 3, 2)) YearInt <- STR_TO_NUM(RIGHT(LastVisitDateString, 4)) LastVisitDate <- SETDATE(DayInt, MonthInt, YearInt)
- MP1 Use of one substring function
- MP2 DayInt, MonthInt and YearInt all correctly extracted
- MP3 Use of STR_TO_NUM x 3
- MP4 SETDATE() function used to convert to a date type and assigned to LastVisitDate
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →