9618/23 · May/June 2023
Download PDFThe following pseudocode represents part of the algorithm for a program. Line numbers are for reference only. 10 DECLARE Sheet4 : ARRAY[1:2, 1:50] OF INTEGER … 100 FOR PCount ← 0 TO 49 101 Sheet4[1, PCount] ← 0 102 Sheet4[2, PCount] ← 47 103 NEXT PCount
The pseudocode contains references to an array. Complete the table by writing the answer for each row. Answer The dimension of the array The name of the variable used as an array index The number of elements in the array
The pseudocode contains two errors. One error is that variable PCount has not been declared. Identify the other error and state the line number where it occurs. Error .......................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... Line number ..............................................................................................................................
The pseudocode does not include a declaration for PCount. State the data type that should be used in the declaration.
The pseudocode statements given in the following table are used in other parts of the algorithm. Complete the table by placing one or more ticks (✓) in each row. The first row has already been completed. Pseudocode statement | Input | Process | Output INPUT MyChoice | ✓ | | OUTPUT FirstName & LastName | | | WRITEFILE YourFile, TextLine | | | READFILE MyFile, TextLine | | | Result ← SQRT(NextNum) | | |
A program stores a date of birth for a student using a variable, MyDOB, of type DATE.
MyDOB has been assigned a valid value corresponding to Kevin’s date of birth. Complete the pseudocode statement to test whether Kevin was born on a Thursday. IF ........................................................................................................................ THEN
A function CheckDate() will take three integer parameters representing a day, month and year of a given date. The function will validate the date of birth for a student that the parameters passed to it represent. For a date to be valid, a student must be at least 18 in year 2020. Two of the parameter values can be checked without reference to the third parameter. Describe these two checks. Check 1 ............................................................................................................................. ........................................................................................................................................... ........................................................................................................................................... Check 2 ............................................................................................................................. ........................................................................................................................................... ........................................................................................................................................... ...........................................................................................................................................
Several values of the parameter representing the day can only be checked completely by referring to the value of one other parameter. Describe this check.
A program processes data using a stack. The data is copied to a text file before the program ends.
The following diagram shows the current state of the stack. The operation of this stack may be summarised as follows: • The TopOfStack pointer points to the last item added to the stack. • The BottomOfStack pointer points to the first item on the stack. • The stack grows upwards when items are added. Stack Pointer Memory location | Value 506 | 505 | WWW ← TopOfStack 504 | YYY 503 | XXX 502 | ZZZ 501 | NNN 500 | PPP ← BottomOfStack An error will be generated if an attempt is made to POP a value when the stack is empty. State the maximum number of consecutive POP operations that could be performed on the stack shown above before an error is generated.
The following operations are performed: 1. POP and store value in variable Data1 2. POP and store value in variable Data2 3. PUSH value AAA 4. PUSH value BBB 5. POP and discard value 6. POP and store value in variable Data2 Complete the diagram to show the state of the stack and the variables after the given operations have been performed.
The data is copied to a text file before the program ends. State an advantage of writing the data from the stack to a text file before the program ends.
A module SaveStack() will write the data from the stack to a text file. Express an algorithm for SaveStack() as five steps that could be used to produce pseudocode. Write the five steps. Step 1 ................................................................................................................................ ........................................................................................................................................... Step 2 ................................................................................................................................ ........................................................................................................................................... Step 3 ................................................................................................................................ ........................................................................................................................................... Step 4 ................................................................................................................................ ........................................................................................................................................... Step 5 ................................................................................................................................ ...........................................................................................................................................
A function MakeString() will: 1. take two parameters: • a count as an integer • a character 2. generate a string of length equal to the count, made up of the character 3. return the string generated, or return "ERROR" if the count is less than 1. For example, the function call: MakeString(3, 'Z') will return the string "ZZZ" Write pseudocode for function MakeString().
A program is designed, coded and compiled without errors. The compiled code is sent for testing.
The program will be tested using the walkthrough method. Additional information will be needed before this method can be used. Identify this additional information and explain why it is needed. Additional information ............................................................................................................... ................................................................................................................................................... Explanation ............................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ...................................................................................................................................................
Testing is completed and the program is made available to users. Some time later, changes are made to the program to improve the speed of response. State the type of maintenance that has been applied to the program.
A procedure Select() will: 1. take two integer values as parameters representing start and end values where both values are greater than 9 and the end value is greater than the start value 2. output each integer value between the start and the end value (not including the start and end values), where the sum of the last two digits is 6, for example, 142.
Write pseudocode for procedure Select(). Parameter validation is not required.
The check performed by procedure Select() on the last two digits is needed at several places in the program and will be implemented using a new function. The new function CheckNum() will: • allow the required sum to be specified (not just 6) • check one number • return an appropriate value. Describe the function interface and two advantages of this modular approach. Interface .................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... Advantage 1 ............................................................................................................................. ................................................................................................................................................... Advantage 2 ............................................................................................................................. ...................................................................................................................................................
A school has a library system which allows students to borrow books for a length of time. Information relating to students and books is stored in text files. Student information includes name, home address, email address, date of birth, tutor and subject choices. Book information includes author, title, subject category, library location and the date that the book was borrowed. A program helps the staff to manage the borrowing of books.

A new module needs to be written to generate emails to send to students who have an overdue book. Students who are sent an email are prevented from borrowing any more books until the overdue book is returned. The process of abstraction has been used when designing the new module. State the purpose of applying abstraction to this problem.
Identify one item of information that is required and one item that is not required in the new module. Justify your choices. Item required ..................................................................................................................... Justification ....................................................................................................................... ........................................................................................................................................... ........................................................................................................................................... Item not required ............................................................................................................... Justification ....................................................................................................................... ........................................................................................................................................... ...........................................................................................................................................
Identify two operations that would be required to process data when an overdue book is returned. Operation 1 ....................................................................................................................... ........................................................................................................................................... Operation 2 ....................................................................................................................... ...........................................................................................................................................
Part of the library program contains program modules with headers as follows: Pseudocode module header PROCEDURE Module-X() PROCEDURE Module-Y(BYREF RA : INTEGER, SA : REAL) PROCEDURE Overlay() FUNCTION Replace(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN FUNCTION Reset(TA : STRING) RETURNS INTEGER Module-X() and Module-Y() are both called from module Overlay(). Complete the structure chart.
A computer shop assembles desktop 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 number for each item in the range “0001” to “5999” inclusive SupplierCode | 3 alphabetic characters | code 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. The programmer has defined the first program module as follows: Module | Description ChangeSupp() | • called with two parameters Code1 and Code2 of type string that represent valid supplier codes • creates a new file NewStock.txt from the contents of the file Stock.txt where any reference to Code1 is replaced by Code2 • returns a count of the number of items that have had their supplier code changed
Write pseudocode for module ChangeSupp().
A new module is required: Module | Description Report_1() | • takes a parameter of type string that represents a SupplierCode • searches the Stock.txt file for each line of item information that contains the given SupplierCode • produces a formatted report of items for the given SupplierCode, for example, for supplier DRG, the output could be: Report for Supplier: DRG Item Description 1234 USB Printer Cable 3m 1273 32GB USB Flash Drive 1350 Mouse Mat 320 x 240mm Number of items listed: 3 Write pseudocode for module Report_1().
The format of the output from module Report_1() from part (b) is changed. The number of items listed is moved to the top of the report as shown in the example: Report for Supplier: DRG Number of items listed: 3 Item Description 1234 USB Printer Cable 3m 1273 32GB USB Flash Drive 1350 Mouse Mat 320 x 240mm Explain why this new layout would increase the complexity of the algorithm.
The algorithm will be modified to produce the report in the new format. The modified algorithm will be implemented so that the file Stock.txt is only read once. Describe the modified algorithm.






