Note AcademyNote Academy

Computer Science · May / June 2023 · Paper 21 · Question 11

0478

As printed in the paper

The question as text

A one-dimensional (1D) array Days[] contains the names of the days of the week. A two-dimensional (2D) array Readings[] is used to store 24 temperature readings, taken once an hour, for each of the seven days of the week. A 1D array AverageTemp[] is used to store the average temperature for each day of the week. The position of any day’s data is the same in all three arrays. For example, if Wednesday is in index 4 of Days[], Wednesday’s temperature readings are in index 4 of Readings[] and Wednesday’s average temperature is in index 4 of AverageTemp[] The temperature readings are in Celsius to one decimal place. Temperatures can only be from –20.0 °C to +50.0 °C inclusive. Write a program that meets the following requirements: • input and validate the hourly temperatures for one week • calculate and store the average temperature for each day of the week • calculate the average temperature for the whole week • convert all the average temperatures from Celsius to Fahrenheit by using the formula Fahrenheit = Celsius * 9 / 5 + 32 • output the average temperature in Celsius and in Fahrenheit for each day • output the overall average temperature in Celsius and in Fahrenheit for the whole week. You must use pseudocode or program code and add comments to explain how your code works. You do not need to declare any arrays, variables or constants; you may assume that this has already been done. All inputs and outputs must contain suitable messages. All data output must be rounded to one decimal place. You will need to initialise and populate the array Days[] at the start of the program.

Read automatically from the paper; the printed page above is exact.

Show the answer and mark scheme

Read the whole answer:

Check if each requirement listed below has been met. Requirements may be met using a suitable built-in function from the programming language used (Python, VB.NET or Java).

On place a SEEN mark if requirement met, cross if no attempt seen, omission mark and/or comment if partially met (see marked scripts).

Use the tables for AO2 and AO3 below to award a mark in a suitable band using a best fit approach, then add up the total: • AO2 (maximum 9 marks)

AO3 (maximum 6 marks)

Data structures required:

The names underlined must match those given in the scenario:

Arrays or lists Days[], Readings[], AverageTemp[]

Variables

WeekLoop, DayLoop, InTemp, TotalDayTemp, TotalWeekTemp, AverageWeekTemp

Requirements (techniques):

R1 Input and store hourly temperatures and validation of input temperatures for each day (with prompts, range check and (nested)iteration)

R2 Calculate, round to one decimal place and store daily average temperatures and calculate the weekly average temperature rounded to one decimal place (iteration, totalling and rounding)

R3 Convert all average temperatures to Fahrenheit (to one decimal place) and output the average temperatures in both Celsius and Fahrenheit. Output with appropriate messages. (output and rounding)

Example 15 mark answer in pseudocode

// meaningful identifiers and appropriate data structures for

// all data required

DECLARE Days : ARRAY[1:7] OF STRING

DECLARE Readings : ARRAY[1:7, 1:24] OF REAL

DECLARE AverageTemp : ARRAY[1:7] OF REAL

DECLARE WeekLoop : INTEGER

DECLARE DayLoop : INTEGER

DECLARE InTemp : REAL

DECLARE TotalDayTemp : REAL

DECLARE TotalWeekTemp : REAL

DECLARE AverageWeekTemp : REAL

// initial population of Days[] array

// input and a loop are also acceptable

Days[1] ← "Sunday"

Days[2] ← "Monday"

Days[3] ← "Tuesday"

Days[4] ← "Wednesday"

Days[5] ← "Thursday"

Days[6] ← "Friday"

Days[7] ← "Saturday"

// input temperatures inside nested loop

FOR WeekLoop ← 1 TO 7

TotalDayTemp ← 0

FOR DayLoop ← 1 TO 24

OUTPUT "Enter temperature ", DayLoop, " for ", Days[WeekLoop]

INPUT InTemp

// validation of input for between -20 and +50 inclusive

WHILE InTemp < -20.0 OR InTemp > 50.0 DO

OUTPUT "Your temperature must be between -20.0 and +50.0 inclusive. Please try again"

INPUT InTemp

ENDWHILE

Readings[WeekLoop, DayLoop] ← InTemp

// totalling of temperatures during the day

TotalDayTemp ← TotalDayTemp + ROUND(InTemp, 1)

NEXT DayLoop

// average temperature for the day

AverageTemp[WeekLoop] ← ROUND(TotalDayTemp / 24,1)

NEXT WeekLoop

// calculate the average temperature for the week

TotalWeekTemp ← 0

FOR WeekLoop ← 1 TO 7

TotalWeekTemp ← TotalWeekTemp + AverageTemp[WeekLoop]

NEXT WeekLoop

AverageWeekTemp ← ROUND(TotalWeekTemp / 7,1)

// outputs in Celsius and Fahrenheit

FOR WeekLoop ← 1 TO 7

OUTPUT "The average temperature on ", Days[WeekLoop], " was ", AverageTemp[WeekLoop], " Celsius and ",

ROUND(AverageWeekTemp * 9 / 5 + 32), 1, " Fahrenheit"

NEXT WeekLoop

OUTPUT "The average temperature for the week was ",

AverageWeekTemp," Celsius and ", ROUND(AverageWeekTemp * 9 / 5 + 32, 1),"

Fahrenheit"

AO2: Apply knowledge and understanding of the principles and concepts of computer science to a given context, including the analysis and design of computational or programming problems

Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.