Lesson 57: Weather week
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
A table of readings
- A weather station takes several readings every day. A 2D array stores them like a table: one row for each day, one column for each reading.
- Two loops, one inside the other, visit every cell: the outer loop picks the day, the inner loop the reading.
- Parallel arrays use the same index for the same thing:
days[1]andreadings[1]are both Tuesday.
Words for this lesson
| Word | Meaning |
|---|---|
| 2D array | a table of values with rows and columns |
| nested loop | a loop inside another loop |
| parallel arrays | arrays where the same index means the same item |
English
readings[d][h]
| Day | h = 0 | h = 1 | h = 2 | h = 3 |
|---|---|---|---|---|
| Mon (d = 0) | 10.0 | 12.0 | 15.0 | 11.0 |
| Tue (d = 1) | −2.5 | 0.5 | 3.0 | 1.0 |
| Wed (d = 2) | 20.4 | 22.6 | 25.1 | 21.2 |
English
In the exam
- 0478/21/M/J/23 Q11 (the long programming question): a 2D array
Readings[]holds 24 hourly temperatures for each of 7 days, with the parallel arraysDays[]andAverageTemp[]. Your program must store each day's average, find the average for the whole week, convert with Fahrenheit = Celsius × 9 / 5 + 32, and output every value rounded to one decimal place with a suitable message. - That question also asks you to validate each input (−20.0 to +50.0): use the range check from lesson 40.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
A weather station stores temperatures in a 2D array: readings[d][h] is reading h of day d (3 days, 4 readings a day). For each day, add up its 4 readings with a loop inside the loop, and store the average in averageTemp[d]. The program prints each day, for example Mon: 12.0 C.
출력을 보려면 '실행'을 클릭하세요.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
Finish the function toF(c): Fahrenheit = Celsius × 9 ÷ 5 + 32. Then also add every day's total to weekTotal, and at the end print the average of all 12 readings: Week: then the value in C and in F, like the day lines. All values have one decimal place.
출력을 보려면 '실행'을 클릭하세요.