Question 1 Report
Fig. 1 shows the route used by a coastal survey team to load observations from a text file into its mapping program. Each record should have three comma-separated fields: a site code, a water temperature in degrees C, and a tide state of HIGH or LOW. At a busy field station, a volunteer may leave a field blank, enter words instead of a temperature, or use an unexpected tide state. The team wants the program to keep processing later records, but it must not add an invalid record to the main data store.
(a) State the data type that should be used for the water-temperature field after it has been checked. [1]
(b) Describe three validation checks the program should apply to one imported record. [3]
(c) Explain why the invalid record should be written to an error log rather than silently discarded. [3]
(d) Write pseudocode for the main loop that reads every line in the file. Valid records must be added to observations; invalid records must cause an error message containing the site code to be added to errorLog. [5]
(a) Water temperature should be stored as a real (floating-point) number after checking, because temperatures can have decimal places. [1]
(b) Three suitable validation checks are:
HIGH or LOW. [1]A realistic temperature range check, for example \(-5\) to \(45\) degrees C, and a site-code format check are also acceptable.
(c) An error log records which records were not imported. Staff can locate and correct the original entry, rather than losing evidence, while invalid data remains out of the main data store. [3]
(d) The loop reads each line until end of file, splits it into fields, then sends valid and invalid records to different destinations.
OPEN "survey.txt" FOR READ
WHILE NOT EOF("survey.txt")
line READLINE("survey.txt")
fields SPLIT(line, ",")
IF validRecord(fields) THEN
ADD fields TO observations
ELSE
ADD "Invalid record: " + fields[0] TO errorLog
ENDIF
ENDWHILE
CLOSE "survey.txt"Opening the file and looping to EOF process every record; splitting obtains the three fields; the IF prevents invalid records entering observations while recording the site code in errorLog. [5]
Everything you need to excel in your exams