The pseudocode algorithm below allows a user to input a new stock item. The random file is searched for the next empty location in the file and the new item is inserted there. A suitable message is displayed if the file is full. Complete this pseudocode. DECLARE Location : INTEGER DECLARE NewStock : STRING DECLARE CurrentStock : STRING DECLARE Stored : BOOLEAN DECLARE Max : INTEGER Max ← 100000 Stored ← FALSE Location ← 1 OUTPUT "Enter the new item you wish to store: " INPUT NewStock WHILE NOT Stored AND Location <= Max GETRECORD "StockList.dat", IF CurrentStock = "" THEN ENDIF ENDWHILE THEN OUTPUT "The new item has not been stored as the file was full." ENDIF CLOSEFILE "StockList.dat"
- DECLARE Location : INTEGER DECLARE NewStock : STRING DECLARE CurrentStock : STRING DECLARE Stored : BOOLEAN DECLARE Max : INTEGER Max ← 100000 Stored ← FALSE Location ← 1 OUTPUT "Enter the new item you wish to store: " INPUT NewStock WHILE NOT Stored AND Location <= Max GETRECORD "StockList.dat", IF CurrentStock = "" THEN ENDIF ENDWHILE THEN OUTPUT "The new item has not been stored as the file was full." ENDIF CLOSEFILE "StockList.dat"[5]
Mark scheme
Marking points from the official mark scheme (May/June 2025). The mark or mark type is shown in brackets.
- [5] One mark for each correctly completed line
- DECLARE Location : INTEGER
- DECLARE NewStock : STRING
- DECLARE CurrentStock : STRING
- DECLARE Stored : BOOLEAN
- DECLARE Max : INTEGER
- Max ← 100000
- Stored ← FALSE
- Location ← 1
- OPENFILE "StockList.dat" FOR RANDOM
- OUTPUT "Enter the new item you wish to store"
- INPUT NewStock
- WHILE NOT Stored AND Location <= Max
- SEEK "StockList.dat", Location
- GETRECORD "StockList.dat", CurrentStock
- IF CurrentStock = "" THEN
- PUTRECORD "StockList.dat", NewStock
- Stored ← TRUE
- ELSE
- Location ← Location + 1
- ENDIF
- ENDWHILE
- IF Stored = FALSE THEN
- OUTPUT "The new stock item has not been stored as the file was full"
- ENDIF
- CLOSEFILE "StockList.dat"
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 →