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-sep...

Assessment: Computer Science 9210 | Paper 1 Mock 01 | Programming (on-screen) Subject: Computer Science - 9210

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.

Text fileValid?yesMain data storenoError log© EAGLE BEACON GLOBAL

(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]

Answer Details

(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:

  • A presence check to ensure site code, temperature, and tide state are all entered. [1]
  • A type check to ensure that temperature can be converted to a number. [1]
  • A lookup check to ensure the tide state is exactly 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]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning