Question

ENGR 200 FALL 2019 P8: TEMPERATURE ANALYSIS (input/output files, if structures, for loops, two-dimensional array, one-dimensional...

ENGR 200 FALL 2019

P8: TEMPERATURE ANALYSIS
(input/output files, if structures, for loops, two-dimensional array, one-dimensional character array)

DUE: November 14, 2019, at 11:59 p.m. US Central Time POINTS: 70

INTRODUCTION:
You are working on development of a new power plant for Centerville, USA. Average monthly temperature data has been collected as part of designing the new power plant, and you are required to develop a computer program that will perform averaging analysis. The input data file is called temp. As you examine the input file, you notice that the first record line is the name of the city and type of data, the second record line contains the control numbers, and the remaining record lines are the average monthly temperatures: 12 rows (January – December) and 5 years (2013 – 2017).

ASSIGNMENT:
Write a C program that will read the data from the input file, such that the city name and type of data are stored in a one-dimensional character array, and the temperatures are store in a two-dimensional array. Manipulate the two-dimensional array to calculate the average temperature for each year and the standard deviation in temperature for each year. Then find the minimum and maximum temperatures and the locations in the array of the minimum and maximum values.

The formula for standard deviation is:

where s is the standard deviation, x is the individual sample values, ̅x is the mean value, Σ is the summation, and n-1 is the number of values in the sample minus 1. In this case, n is 12 (number of months in the year) and ̅x is the yearly average temperature.

Print the output to the computer screen and to an output file called temp_report. Illustrated below is the output style for the computer screen and the output file.














OUTPUT FORMAT:
*****************************************************
Centerville-Temperature

Year 1 Year 2 Year 3 Year 4 Year 5

Month 1 xx xx xx xx xx   
Month 2 . . . . .   
Month 3 . . . . .   
Month 4 . . . . .   
Month 5   
Month 6   
Month 7
Month 8
Month 9   
Month 10   
Month 11   
Month 12   

Average: xx.xx xx.xx xx.xx xx.xx xx.xx
St. Dev.: xx.xx xx.xx xx.xx xx.xx xx.xx

REPORT SUMMARY:
Minimum temp is xx degrees F in month xx, year x.
Maximum temp is xx degrees F in month xx, year x.
*****************************************************

Centerville-Temperature
12 5
10.8 4.6 16.2 13.35 14.95
12.65 4.7 7.9 23.8 24.35
17.25 22.45 33.6 38.35 29.65
33.85 40.35 47.15 43.85 45.65
57.6 57 55 60.6 57
67.55 67.2 67.15 68.8 67.85
71.75 69.4 72.55 71.85 72.1
70.95 69.3 69.45 70.25 66.8
63.45 60.85 65.6 62.7 61.95
44.8 48.45 50.8 49.35 47.5
23.3 22.95 36.3 41.8 28.4
4.2 21.2 23.2 16.15 14.45

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// temperatures.txt

Centerville-Temperature
12 5
10.8 4.6 16.2 13.35 14.95
12.65 4.7 7.9 23.8 24.35
17.25 22.45 33.6 38.35 29.65
33.85 40.35 47.15 43.85 45.65
57.6 57 55 60.6 57
67.55 67.2 67.15 68.8 67.85
71.75 69.4 72.55 71.85 72.1
70.95 69.3 69.45 70.25 66.8
63.45 60.85 65.6 62.7 61.95
44.8 48.45 50.8 49.35 47.5
23.3 22.95 36.3 41.8 28.4
4.2 21.2 23.2 16.15 14.45

______________________

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <math.h>

int main() {
int rows, cols, i, j;
char name[50];
FILE * f1, * f2;

//Opening the input file in read mode;
f1 = fopen("temperatures.txt", "r");
if (f1 == NULL) {
printf("** input_numbers.txt File not found **\n");
} else {
fscanf(f1, "%s%d%d", & name, & rows, & cols);

float temps[rows][cols];
float avgs[rows];

//Reading the data from the file and populate into array
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
fscanf(f1, "%f", & temps[i][j]);
}
}
//closing the input file
fclose(f1);

//Opening the output file
f2 = fopen("temp_report.txt", "w");
fprintf(f2, "%s\n", "************************************************");
printf("*************************************************\n");
fprintf(f2, "\t%s\n", "Year 1 Year 2 Year 3 Year 4 Year5");
printf("\tYear 1 Year 2 Year 3 Year 4 Year5\n");

for (i = 0; i < rows; i++) {
printf("Month %d:", (i + 1));
fprintf(f2, "Month %d:", (i + 1));

for (j = 0; j < cols; j++) {
printf("%-6.2f ", temps[i][j]);
fprintf(f2, "%-6.2f ", temps[i][j]);
}
printf("\n");
fprintf(f2, "\n");

}
float sum = 0, avg = 0.0;
printf("Average:");
fprintf(f2, "%s", "Average:");

//calculating the average
for (i = 0; i < cols; i++) {
sum = 0.0;
for (j = 0; j < rows; j++) {
sum += temps[j][i];
}
avg = sum / rows;
avgs[i] = avg;
printf("%-6.2f ", avg);
fprintf(f2, "%-6.2f ", avg);
}
printf("\nSt. Dev.:");
fprintf(f2, "%s", "\nSt. Dev.:");
float standardDev, sum2 = 0.0;

//calculating the standard deviation
for (i = 0; i < cols; i++) {
sum2 = 0.0;
for (j = 0; j < rows; j++) {
sum2 += pow((temps[j][i] - avgs[i]), 2);
}
standardDev = sqrt((sum2) / (rows));

printf("%-6.2f ", standardDev);
fprintf(f2, "%-6.2f ", standardDev);
}

printf("\nREPORT SUMMARY:\n");
fprintf(f2, "\n%s\n", "REPORT SUMMARY:\n");

float min, max;
int minindx = 0, maxindx = 0, minYear = 0, maxYear = 0;
min = temps[0][0];
max = temps[0][0];

//finding the min amd max temps
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
if (min > temps[i][j]) {
min = temps[i][j];
minindx = i;
minYear = j;
}
if (max < temps[i][j]) {
max = temps[i][j];
maxindx = i;
maxYear = j;
}

}
}

printf("Minimum temp is %.2f degrees F in month %d, year %d.\n", min, (minindx + 1), (minYear + 1));
printf("Maximum temp is %.2f degrees F in month %d, year %d.\n", max, (maxindx + 1), (maxYear + 1));
fprintf(f2, "Minimum temp is %.2f degrees F in month %d, year %d.\n", min, (minindx + 1), (minYear + 1));
fprintf(f2, "Maximum temp is %.2f degrees F in month %d, year %d.\n", max, (maxindx + 1), (maxYear + 1));
fprintf(f2, "%s\n", "************************************************");
printf("*************************************************\n");

fclose(f2);

}

return 0;

}

______________________________

Output: (Console)

___________________________

// temp-report.txt (output file)


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
ENGR 200 FALL 2019 P8: TEMPERATURE ANALYSIS (input/output files, if structures, for loops, two-dimensional array, one-dimensional...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • INTRODUCTION You are working on development of a new power plant for Centerville, USA. Average monthly...

    INTRODUCTION You are working on development of a new power plant for Centerville, USA. Average monthly temperature data has been collected as part of designing the new power plant, and you are required to develop a computer program that will perform averaging analysis. The input data file is called temp. As you examine the input file, you notice that the first record line is the name of the city and type of data, the second record line contains the control...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • Problem: You will write a program to compute some statistics based on monthly average temperatures for...

    Problem: You will write a program to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for 1901, the...

  • Problem: You will write a program a C++ to compute some statistics based on monthly average...

    Problem: You will write a program a C++ to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

  • I need this asap. C++ please A A Ap Aa Consolas 14 AaBbCcDd AaBbCcDd AaBbCc Editing...

    I need this asap. C++ please A A Ap Aa Consolas 14 AaBbCcDd AaBbCcDd AaBbCc Editing ste 1 No Spac.. Heading 1 В I 1 Normal x A U A v ab х. Dictate ipboard Font Paragraph Styles Voice Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program...

  • Hello! I have this python Homework due tonight that I don't know how to do. Here...

    Hello! I have this python Homework due tonight that I don't know how to do. Here is a document with the data in the csv file, as I didn't know how to share it https://docs.google.com/document/d/1bDJVR2MqWKInvw5u0r3fOG3-CBmu3BEiPZwlaq_CShQ/edit?usp=sharing Activity #3: On the class website is a CSV file containing weather data from Coulter Field (in Bryan) for 3 years (1 day is missing for some reason!); the data was taken from Weather Underground (wunderground.com). There are different versions of the file for Windows...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT