Question

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 not C++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 arrayo f th e 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) andx 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 Month 2 Month 3 Month 4 Month5 Month 6 Month 7 Month 8 Month 9 Month 10 Month 11 Month 12 Xx Xx Average St. Dev. xx.xx 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.

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

The code is followed by the output snapshot. The filename should be "temp" for input and "temp_report" for output. If other names are needed , they may be modified accordingly.

#include <stdio.h>
#include <math.h>

int main()
{
    FILE *in, *out;
    float data[100][100]; /* to handle files with a maximum of 100 years or months */
    float average[100], stdev[100];
    char city_data[100];
    int no_month, no_year;
    int minmm, minyy, maxmm, maxyy;

    int i, j; /* loop variables */

    in = fopen("temp", "r");
    out = fopen("temp_report", "w");

    if(in == NULL || out == NULL)
    {
        printf("Error opening files\n");
        return -1;
    }

    /* start reading file */
    fscanf(in, "%s", city_data);
    fscanf(in, " %d %d", &no_month, &no_year);

    for(i = 0; i < no_month; i++)
    {
        for(j = 0; j < no_year; j++)
        {
            fscanf(in, " %f", &data[i][j]);
        }
    }

    fclose(in);

    /* process data */
    minmm = minyy = maxmm = maxyy = 0;

    for(j = 0; j < no_year; j++)
    {
        average[j] = 0.0f;
        for(i = 0; i < no_month; i++)
        {
            average[j] += data[i][j];

            /* update minimum and maximum */
            if(data[i][j] < data[minmm][minyy])
            {
                minmm = i;
                minyy = j;
            }

            if(data[i][j] > data[maxmm][maxyy])
            {
                maxmm = i;
                maxyy = j;
            }
        }
        average[j] /= no_month;
    }

    /* std deviation */
    for(j = 0; j < no_year; j++)
    {
        /* loop for summation of (x - x')^2 */
        stdev[j] = 0.0f;
        for(i = 0; i < no_month; i++)
        {
            stdev[j] += pow(data[i][j] - average[j], 2);
        }

        stdev[j] /= (no_month - 1);
        stdev[j] = sqrt(stdev[j]);
    }

    /* Print to file and console */
    printf("***********************************************************\n");
    fprintf(out, "***********************************************************\n");

    printf("                %s\n\n", city_data);
    printf("           ");
    fprintf(out, "                %s\n\n", city_data);
    fprintf(out, "           ");
    for(j = 0; j < no_year; j++)
    {
        printf("   Year %d", j+1);
        fprintf(out, "   Year %d", j+1);
    }
    printf("\n\n");
    fprintf(out, "\n\n");

    for(i = 0 ; i < no_month; i++)
    {
        printf("Month %2d   ", i+1);
        fprintf(out, "Month %2d   ", i+1);
        for(j = 0; j < no_year; j++)
        {
            printf("    %5.2f", data[i][j]);
            fprintf(out, "    %5.2f", data[i][j]);
        }
        printf("\n");
        fprintf(out, "\n");
    }

    printf("\nAverage:   ");
    fprintf(out, "\nAverage:   ");
    for(j = 0; j < no_year; j++)
    {
        printf("    %5.2f", average[j]);
        fprintf(out, "    %5.2f", average[j]);
    }

    printf("\nSt. Dev.: ");
    fprintf(out, "\nSt. Dev.: ");
    for(j = 0; j < no_year; j++)
    {
        printf("    %5.2f", stdev[j]);
        fprintf(out, "    %5.2f", stdev[j]);
    }

    printf("\n\nREPORT SUMMARY:\n");
    printf("Minimum temp is %5.2f degrees F in month %2d, year %d.\n", data[minmm][minyy], minmm+1, minyy+1);
    printf("Maximum temp is %5.2f degrees F in month %2d, year %d.\n", data[maxmm][maxyy], maxmm+1, maxyy+1);

    printf("***********************************************************\n");

    fprintf(out, "\n\nREPORT SUMMARY:\n");
    fprintf(out, "Minimum temp is %5.2f degrees F in month %2d, year %d.\n", data[minmm][minyy], minmm+1, minyy+1);
    fprintf(out, "Maximum temp is %5.2f degrees F in month %2d, year %d.\n", data[maxmm][maxyy], maxmm+1, maxyy+1);

    fprintf(out, "***********************************************************\n");
  
    fclose(out);
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
INTRODUCTION You are working on development of a new power plant for Centerville, USA. Average monthly...
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
  • 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....

  • 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 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:...

  • Programming problem: Input Fahrenheit temperatures, storing them in an array, then display a table of those...

    Programming problem: Input Fahrenheit temperatures, storing them in an array, then display a table of those temperatures along with their Celsius equivalents. Do this as a modification of A06 if you wish, but 1. One temperature at a time, prompt for and input a record of 10 daily temperatures in Fahrenheit. 2. After that record has been input, use a second counting loop to display a table of data in which: at minimum: Use a counting loop. Store these values...

  • ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program...

    ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program at the bottom to sort an array using selection sort. Write a selection sort to report out the sorted low values: lowest to highest. Write another to report out the sorted high values – highest to lowest. Last but not least, the program should output all the values in the array AND then output the 2 requested sorted outputs. -----> MY OLD PROGRAM BELOW...

  • Problem: A local amateur meteorologist has been recording daily high temperatures throughout the month of June....

    Problem: A local amateur meteorologist has been recording daily high temperatures throughout the month of June. He would like you to write a program to compute some statistics based on the data he has collected. He has placed each daily high temperature on a separate line in a file named “summer_temps.txt”. The high temperatures are in order so that the first one is for June 1, the second is for June 2, and so on. The statistics that the meteorologist...

  • Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month...

    Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month and stored in a file called temperature.txt. Write a complete C Language program that reads the stored temperatures, one at a time, from the file temperature.txt and converts the read temperature to its equivalent in Celsius. Your program should store each converted temperature in an output file called results.txt. Your program should find the average, the minimum, and the maximum temperatures in Celsius and...

  • Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month...

    Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month and stored in a file called temperature.txt. Write a complete C language program that reads the stored temperatures, one at a time, from the file temperature.txt and converts the read temperature to its equivalent in Celsius. Your program should store each converted temperature in an output file called results.txt. Your program should also find the average, the minimum, and the maximum temperatures in Celsius...

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