A computer shop assembles computers using items bought from several suppliers. A text file Stock.txt contains information about each item. Information for each item is stored as a single line in the Stock.txt file in the format: <ItemNum><SupplierCode><Description> Item information is as follows: Format Comment ItemNum 4 numeric characters unique for each item in the range "0001" to "5999" inclusive SupplierCode 5 alphabetic characters to identify the supplier of the item Description a string a minimum of 12 characters The file is organised in ascending order of ItemNum and does not contain all possible values in the range. A programmer has started to define program modules as follows: Module Description SuppExists() (already written) • called with a parameter of type string representing a supplier code • returns TRUE if the supplier code is already in use, otherwise returns FALSE IsNewSupp() • called with a parameter of type string representing a new supplier code • returns TRUE if the string only contains alphabetic characters (either upper or lower case) and the supplier code is not already in use, otherwise returns FALSE
- (a)Write pseudocode for module IsNewSupp(). Module SuppExists() has already been written and should be used as part of your solution. Module SuppExists() will generate a run-time error if the given parameter is not 5 characters in length.[7]
- (b)A new module has been defined: Module CheckNewItem() Description • called with a parameter of type string representing a line of item information • checks to see whether an item with the same ItemNum already exists in the file • returns TRUE if the ItemNum is not already in the file, otherwise returns FALSE Write efficient pseudocode for module CheckNewItem().[7]
- (c)(i)The program modules SuppExists(), IsNewSupp() and CheckNewItem() are part of a group of modules that are combined to create a complete stock control program. Each module in the program is tested individually during development and is debugged as necessary. It is then added to the program and further testing performed. Identify this method of testing.[1]
- (c)(ii)One of the modules does not work properly when it is added to the program. Describe a testing method that can be used to address this problem so that testing can continue and other modules can be added.[2]
- (d)A new module AddItem() will be used to add information to the Stock.txt file. State the file mode that should be used for the algorithm within this module.[1]
- (e)A new module FindItem() searches for a given item in the Stock.txt file, which is already organised in ascending order of ItemNum. Describe how this organisation may improve the efficiency of the algorithm.[3]
Mark scheme
Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.
- [7] FUNCTION IsNewSupp(ThisString : STRING) RETURNS BOOLEAN DECLARE Index : INTEGER DECLARE ThisChar : CHAR IF LENGTH(ThisString) <> 5 THEN RETURN FALSE ENDIF // invalid SupplierCode length IF SuppExists(ThisString) THEN RETURN FALSE // SupplierCode already exists ENDIF FOR Index ← 1 TO 5 ThisChar ← TO_LOWER(MID(ThisString, Index, 1)) IF ThisChar < 'a' OR ThisChar > 'z'THEN RETURN FALSE ENDIF NEXT Index RETURN TRUE ENDFUNCTION Mark as follows: 1 Check ThisString is exactly 5 characters in length 2 Use of SuppExists() with a string of 5 characters as a parameter 3 Loop for 5 iterations // loops for length of string parameter 4 Extract a character in a loop 5 Test if char is alphabetic in a loop 6 ...catering for both upper and lower case 7 Return Boolean following a reasonable attempt
- [7] FUNCTION CheckNewItem(NewLine : STRING) RETURNS BOOLEAN DECLARE NotFound : BOOLEAN DECLARE NewItemNum, ThisItemNum, ThisLine : STRING Not Found ← TRUE OPENFILE "Stock.txt" FOR READ NewItemNum ← LEFT(NewLine, 4) ThisItemNum ← "0000" //rogue initial value WHILE NOT EOF("Stock.txt") AND NotFound = TRUE AND ThisItemNum < NewItemNum READFILE("Stock.txt", ThisLine) //brackets optional ThisItemNum ← LEFT(ThisLine, 4) IF ThisItemNum = NewItemNum THEN NotFound ← FALSE ENDIF ENDWHILE CLOSEFILE "Stock.txt" RETURN NotFound ENDFUNCTION Mark as follows: 1 Open Stock.txt in READ mode and subsequently close 2 Extract NewItemNum from parameter 3 Conditional loop until EOF ("Stock.txt") 4 OR NewItemNum found 5 OR when ThisItemNum < NewItemNum 6 Read a line from Stock.txt AND extract ThisItemNum in a loop 7 If ThisItemNum = NewItemNum then terminate loop / set flag in a loop 8 Return Boolean after reasonable attempt Max 7 marks Max 6 if function wrapper (heading and ending) missing or incorrect
- [1] Integration testing
- [2] Two marks for the description: • A dummy/simple module is written to replace the module that does not work properly • The dummy/simple module will return an expected value // will output a message to show it has been called
- [1] Append
- [3] One mark for each part: • The algorithm / search / iteration can stop /only iterates • if the current value read from the file // current line in file • is greater than the value being searched for
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 →