A business sells a single product. Customers can purchase one or more of this product. Each sale has an ID and a quantity, for example "ABC" and 2 The business needs a program to store the data about the sales in a circular queue data structure.
- (a)Write program code to declare a record structure, SaleData, to store the data about each sale.[2]
- (b)Write program code to: • declare a global array, CircularQueue, of 5 items to store the sale records • declare the global pointers Head and Tail • declare the global variable NumberOfItems • initialise all elements of the array CircularQueue to an empty record, where the ID is null ("") and quantity is -1 • initialise Head, Tail and NumberOfItems to 0[4]
- (c)The function Enqueue(): • takes a new record as a parameter • inserts the record in the circular queue at the element pointed to by Tail • updates pointers and other variables as required • returns -1 if the circular queue is full • returns 1 if the record is stored successfully. Write program code for the function Enqueue().[6]
- (d)The function Dequeue(): • returns a null or empty record if the circular queue is empty • returns the first record in the queue if the circular queue is not empty • updates pointers and other variables as required. Write program code for the function Dequeue().[6]
- (e)The procedure EnterRecord(): • takes an ID and quantity as input and creates a sale record • uses Enqueue () to insert the record in the circular queue • outputs "Full" if the record was not inserted in the circular queue • outputs "Stored" if the record was inserted in the circular queue. Write program code for the procedure EnterRecord().[5]
- (f)(i)The following sale records need to be entered into the program: ID Quantity ADF 10 OOP 1 BXW 5 XXZ 22 HQR 6 LLP 3 Amend the main program to: • use EnterRecord() to input the six records in the table • use Dequeue () to remove one record • output either the ID and quantity of the removed record, or an error message if the circular queue is empty • use EnterRecord() to input the record with the ID "LLP" for a second time • output the ID and quantity for all the records currently stored in the array CircularQueue. Write program code to perform these tasks.[4]
- (f)(ii)Test your program. Take a screenshot of the output.[1]
Mark scheme
Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.
- [1] Record declaration named SaleData // class declaration (and end) named SaleData...
- [1] ...SaleID declared as string, Quantity as integer in record // if a class then a constructor assigning attributes SaleID and Quantity
- [1] Global array CircularQueue of 5 items of type SaleData
- [1] Global variables Head, Tail and NumberOfItems all initialised to 0
- [1] One record declared setting ID to "" and Quantity to -1
- [1] ...stored in all 5 array elements
- [1] Function Enqueue() header (and end) taking one parameter (type SaleData)
- [1] Checks if queue is full ...
- [1] and returns -1
- [1] (otherwise) Inserts parameter to CircularQueue[Tail]
- [1] increments Tail and resets to 0 if 5
- [1] Increments number of items and returns 1
- [1] Function header Dequeue() (and end where appropriate)
- [1] Checking if queue is empty...
- [1] ....and returning appropriate empty/null record/object/list element
- [1] (Otherwise) returning the item at Head
- [1] Incrementing Head and changing value 0 if it is 4/5
- [1] Decrement number of items
- [1] Procedure header EnterRecord (and end where appropriate) (ignore parameters)
- [1] Takes as input an ID (string) and quantity (integer)
- [1] Creates a record/object using inputs
- [1] Calls Enqueue () with record as parameter and stores/uses return value
- [1] Outputs "Full" and "Stored" in correct places
- [1] Calling EnterRecord() 6 times before dequeue
- [1] Calling Dequeue() and storing/using return value
- [1] checking if an empty record is returned and outputting either the ID and quantity of returned record or outputting the error message if empty record
- [1] Calling EnterRecord() again after dequeue
- [1] Output the ID and quantity for all the records currently stored in CircularQueue
- [1] 1 mark for screenshot showing: Data for 6 records input, 5 messages stating (e.g.) stored and 1 message stating (e.g.) full, 1 output of ADF 10 (dequeued), Repeat successful input of LLP 3, Output of the 5 records
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 →