A greenhouse temperature monitoring system takes a reading every hour for 24 hours. An array Temps[0:23] stores the readings (index represents the hour). Te...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

Question 1 Report

A greenhouse temperature monitoring system takes a reading every hour for 24 hours. An array Temps[0:23] stores the readings (index represents the hour).

Temps = [18, 17, 16, 15, 15, 16, 18, 20, 22, 24, 26, 28,
         30, 31, 30, 28, 26, 24, 22, 20, 19, 18, 18, 17]

(a) Write pseudocode to find the highest and lowest temperatures and the hours they occurred. [2]

Answer Details

(a) The algorithm finds the highest and lowest temperatures along with the hours at which they occurred by maintaining tracking variables initialised to the first element.

DECLARE Highest : REAL
DECLARE Lowest : REAL
DECLARE HighHour : INTEGER
DECLARE LowHour : INTEGER
DECLARE h : INTEGER
Highest ← Temps[0]
Lowest ← Temps[0]
HighHour ← 0
LowHour ← 0
FOR h ← 1 TO 23
    IF Temps[h] > Highest THEN
        Highest ← Temps[h]
        HighHour ← h
    ENDIF
    IF Temps[h] < Lowest THEN
        Lowest ← Temps[h]
        LowHour ← h
    ENDIF
NEXT h
OUTPUT "Highest: ", Highest, " at ", HighHour, ":00"
OUTPUT "Lowest: ", Lowest, " at ", LowHour, ":00"

Both Highest and Lowest are initialised to Temps[0] (the reading at midnight, 18 degrees). [1] The loop starts from index 1 and compares each subsequent reading. [1] When a higher temperature is found, both the value and its hour index are updated. [1] When a lower temperature is found, both Lowest and LowHour are updated. [1]

From the data: the highest temperature is 31 at hour 13 (1:00 PM). The lowest temperatures are 15 at hours 3 and 4; since the first occurrence is found first, the output is hour 3 (3:00 AM).

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