In a Matlab text by Gilat a problem presents the relationship between temperatures in New York…
In a Matlab text by Gilat a problem presents the relationship between temperatures in New York City and Denver, Colorado during the month of January, 2014. According to the U.S. National Oceanic and Atmospheric Administration, the January Fahrenheit high temperatures for New York City and Denver, Colorado were:
Date |
New York City Temperature (degrees Fahrenheit) |
Denver Temperature (degrees Fahrenheit) |
1 |
33 |
39 |
2 |
33 |
48 |
3 |
18 |
61 |
4 |
29 |
39 |
5 |
40 |
14 |
6 |
55 |
37 |
7 |
19 |
43 |
8 |
22 |
38 |
9 |
32 |
46 |
10 |
37 |
39 |
11 |
58 |
55 |
12 |
54 |
46 |
13 |
51 |
46 |
14 |
52 |
39 |
15 |
45 |
54 |
16 |
41 |
45 |
17 |
45 |
52 |
18 |
39 |
52 |
19 |
36 |
62 |
20 |
45 |
45 |
21 |
33 |
62 |
22 |
18 |
40 |
23 |
19 |
25 |
24 |
19 |
57 |
25 |
28 |
60 |
26 |
34 |
57 |
27 |
44 |
20 |
28 |
21 |
32 |
29 |
23 |
50 |
30 |
30 |
48 |
31 |
39 |
28 |
Create a new project in Visual Studio. Then create a text file inside the project with three columns, with dates in the first column, with New York temperatures in the second column, and with corresponding Denver temperatures in the column on the right. (You can probably copy and paste values from this assignment document into the text file.) Include the number 31 as the first entry in your data file. Do not include column labels in the data file. Save the file in the project folder.
In the program, declare arrays for dates, New York temperatures, and Denver temperatures with 31 elements each (the maximum number of dates in any month) as well as other necessary variables. Declare pointers to files for input and output. Open the input file for reading and check to make sure it opened successfully. Also, open the output file for writing and check to see that the output file opened successfully.
Read in the number of days in the month. Then read in each line of data into the three arrays, using a for loop. Your loop counter (array subscript) will start with the value 0 and continue until the number of days -1 is reached.
Note: You could also read values in using a while loop in which case you would not include the number 31 at the beginning of the file. The while header line would look something like this:
while((fscanf(fpIn, “%d%d%d”, &day[k] , &NY[k], &DEN[k])) == 3) since there are 3 conversions per line.
Using separate for loops for each calculation below, after all the temperatures have been read in, calculate the following (do not determine by inspection). Do not do all the calculations in the same loop. Place a comment at the beginning of each loop explaining the goal of each loop and how it is being satisfied. All results are to be written to an output file (not to the black screen).
a. Determine in a for loop the sum of temperatures for the month in New York and the sum of temperatures for the month in Denver. Outside of this loop, find the average temperature in each city for the month, and print the averages to your output file.
b. Find and print to your output file the number of days the temperature was above average in each city.
c. Find and print to the output file the highest temperature in New York and the date on which it occurred.
d. Find and print the dates on which the temperature in New York was greater than the temperature in Denver. These dates can be printed from the loop in which they are determined.
All outputs should be written to your output file. Close the files at the end of the program. Submit the output file along with with your .c file to Canvas. This program can be done completely in function main.