A teacher is designing a program to perform simple syntax checks on programs written by students. Student programs are submitted as text files, which are known as project files. A project file may contain blank lines. The teacher has defined the first program module as follows: Module CheckFile() Description • takes the name of an existing project file as a parameter of type string • returns TRUE if the file is valid (it contains at least 10 non-blank lines), otherwise returns FALSE
- (a)Write pseudocode for module CheckFile().[7]
- (b)CountErrors() is called to check the project file Jim01Prog.txt and to stop if more than 20 errors are found. Write the pseudocode statement for this call.[2]
- (c)Write pseudocode for module CountErrors(). Assume CheckFile() and CheckLine() have been written and can be used in your solution.[8]
- (d)Module CheckLine() includes a check for syntax errors. Two examples of syntax error that cannot be detected from examining a single line are those involving selection and iteration. Give two other examples.[2]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2022). The mark or mark type is shown in brackets.
- [1] (a) Function heading and ending including parameter and return type
- [1] (a) Declaration and initialisation of local Integer for Count
- [1] (a) OPEN in READ mode and CLOSE
- [1] (a) Conditional loop until EOF ()
- [1] (a) Read a line in a loop
- [1] (a) If non-blank, increment count in a loop
- [1] (a) Terminate loop when 10 non-blank lines have been read
- [1] (a) Return Boolean in both cases
- FUNCTION CheckFile(ThisFile : STRING) RETURNS BOOLEAN DECLARE Valid : BOOLEAN DECLARE ThisLine : STRING DECLARE Count : INTEGER Count <- 0 Valid <- FALSE OPEN ThisFile FOR READ WHILE NOT EOF(ThisFile) AND Valid = FALSE READFILE ThisFile, ThisLine IF ThisLine <> "" THEN Count <- Count + 1 IF Count > 9 THEN Valid <- TRUE ENDIF ENDIF ENDWHILE CLOSEFILE ThisFile RETURN Valid ENDFUNCTION
- [1] (b) Module name, at least one parameter in brackets and one parameter correct
- [1] (b) Completely correct statement
- CALL CountErrors("Jim01Prog.txt", 20)
- [1] (c) Procedure heading and ending including parameters
- [1] (c) Declaration and initialisation of local Integer value for ErrCount
- [1] (c) Use of CheckFile(),output message and terminate if it returns FALSE
- [1] (c) Conditional loop until EOF ()
- [1] (c) ...or ErrCount > MaxErrors
- [1] (c) Read line and use as parameter to CheckLine() in a loop
- [1] (c) Test return value and increment ErrCount if non-zero in a loop
- [1] (c) Output either message once only as appropriate
- PROCEDURE CountErrors(ThisFile : STRING, MaxErrors : INTEGER) DECLARE ErrCount, ThisError : INTEGER DECLARE ThisLine : STRING ErrCount <- 0 IF CheckFile(ThisFile) = FALSE THEN OUTPUT "That program file is not valid" ELSE OPEN ThisFile FOR READ REPEAT READFILE ThisFile, ThisLine ThisError <- CheckLine(ThisLine) IF ThisError <> 0 THEN ErrCount <- ErrCount + 1 ENDIF UNTIL ErrCount > MaxErrors OR EOF(ThisFile) IF EOF(ThisFile) = FALSE THEN OUTPUT "Check terminated – too many errors" ELSE OUTPUT "There were ", ErrCount, " errors." ENDIF CLOSEFILE ThisFile ENDIF ENDFUNCTION
- [1] (d) Incorrect block structure. Missing keyword denoting part of block (for example ENDPROCEDURE, ENDFUNCTION, ENDTYPE)
- [1] (d) Data type errors, for example, assigning an integer value to a string
- [1] (d) Identifier used before it is declared
- [1] (d) Incorrect parameter use
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 →