A teacher is designing a program to process pseudocode projects written by her students. The program analyses a student project and extracts information about each module that is defined (each procedure or function). This information is stored in a global 2D array ModInfo of type string. A module header is the first line of a module definition and starts with either of the keywords PROCEDURE or FUNCTION. An example of part of the array is given below. Row 10 of the array shows that a procedure header occurs on line 27 and row 11 shows that a function header occurs on line 35. "P" represents a procedure and "F" represents a function: x = 1 | x = 2 | x = 3 ---|---|--- ModInfo [10, x] | "27" | "P" | "MyProc(Z : CHAR)" ModInfo [11, x] | "35" | "F" | "MyFun(Y : CHAR) RETURNS BOOLEAN" The string stored in column 3 is called the module description. This is the module header without the keyword. A valid module header will: • be at least 13 characters long • start with the keyword PROCEDURE or FUNCTION. The keyword may appear in either upper or lower case (or a mix of both) and must be followed by a space character. The teacher has defined the first program module as follows: Module | Description ---|--- Header() | • called with a parameter of type string representing a line of pseudocode • if the line is a valid procedure header, returns a string: "P<Module description>" • if the line is a valid function header, returns a string: "F<Module description>" • otherwise, returns an empty string For example, given the string: "FUNCTION Zap(X : INTEGER) RETURNS CHAR" Header() returns the string: "FZap(X : INTEGER) RETURNS CHAR"
- (a)Write pseudocode for module Header().[7]
- (b)A new module is required: Module | Description ---|--- FindModules() | • called with a parameter of type string representing a student project file name • uses module Header() to check each line of the project • assigns values to the ModInfo array for each module declaration in the student project As a reminder, the previous example of part of the array is repeated below: x = 1 | X = 2 | X 3 ---|---|---|--- ModInfo [10, x] | "27" | "P" | "MyProc(Z : CHAR)" ModInfo [11, x] | "35" | "F" | "MyFun(Y : CHAR) RETURNS BOOLEAN" Write pseudocode for module FindModules(). Assume that the array contains enough rows for the number of modules in each project.[8]
Mark scheme
Marking points from the official mark scheme (May/June 2024). The mark or mark type is shown in brackets.
- [1] (a) Function heading, parameter, return type and ending
- [1] (a) Check that the line is at least 13 characters long before attempting to extract and return empty string
- [1] (a) Attempt at: Extract characters, 9 or 10 characters, corresponding to keyword plus space and compare with appropriate keyword plus space
- [1] (a) Completely correct MP3
- [1] (a) Use of type case conversion to allow for 'any case'
- [1] (a) Calculation of 'rest of line' and concatenation with 'P or 'F'
- [1] (a) Return string
- [1] (b) Open file in READ mode and subsequently close
- [1] (b) Loop to EOF(FileName)
- [1] (b) Read a line from the file and maintain LineNum in a loop
- [1] (b) Call Header() and use return value in a loop
- [1] (b) Test return value for "" in a loop
- [1] (b) Attempt at all three-array assignment for all columns in correct row
- [1] (b) Correct values assigned to all columns of array
- [1] (b) Maintain correct array row index
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 →