In: Computer Science
An amateur meteorologist keeps a list of daily temperatures and wants a program to calculate how many times the maximum temperature occurred. For example, if the list of temperatures is [21, 24, 24, 23, 20, 19, 21, 24], the maximum of 24 occurs 3 times.
a.Consider the problem of calculating how many times the maximum temperature occurs.
b.Write three tests for this problem. The inputs should be different from the example given in the scenario description above. At least one of your tests must be a borderline case. Present the tests in a table, with a column for each input and output, and an extra column with a brief explanation of why you selected each test, as is done for example in Block 2 Part 2 Activity 2.10.
c.Decompose the problem into sub-problems. Use the > notation and state in brackets the type of the problem and of each sub-problem, following the example in Block 2 Part 2 Activity 2.44.
Choose the patterns for the subproblem types you identified, instantiate the patterns into an algorithm, and translate the algorithm into code.'
Answer for Part (a)
In this problem, we are trying to find the occurrence of maximum temperature (which is 24 & occurs 3 times)
The inputs in the program is the array of temperature list i.e. [t1, t2, t3.........., tn] where the size of the array will be n.
Therefore, first admissible input will be n which is the number of temperatures user wants. And based on that, we can ask user to input t1, t2 t3 upto tn
The output will be the largest element of the array with its frequency of occurrence.
Inputs (2 inputs) | Number of temperatures , say n -> must be an integer (1 or more) |
[t1, t2, t3, t4.......tn] -> Positive Integers, Negative Integers, Floating point numbers (decimal numbers). | |
Outputs (2 outputs) | Max temp (Largest no. of array) |
No.of occurrences of largest no. in array |
Answer for Part (b)
Inputs | Outputs | Brief Explanation |
6 inputs -> [31.5 , 32.5 , 33.6, 34.8, 35.5 , 35.8] |
35.8 (max temp) 1 (single occurrence) |
This test case is to show that if the temperatures are in decimals |
8 inputs -> [-1,-2,-8, -7, -6, -4, -1, -5] |
-1 (max temp) 2 occurrences |
This test case is to show that if all the temperature is in negative, then least negative is the maximum temperature |
12 inputs -> [-1, -2, -3, 3, 2 , 0, -3, 2, 5, 4 , 5, 3] |
5 (max temp) 2 occurrences |
This test case contains positive as well as negative temperatures |