Question

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 and saves the results in the output file. Use data type double for input and output temperatures.

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

Solution==================================================================

#include <stdio.h>
#include <stdlib.h>
#include <float.h>


int main(int argc, char *argv[]) {

   FILE *fp;
   FILE *fpOut;
  
   fp=fopen("temprature.txt","r");       //File from where to read
   fpOut=fopen("celsius.txt","w");       //File from where to write
      
   double farenheitData=0;               //To store running farenhiet data from file
   double maxCelcius=DBL_MIN;           //To store max of Celsius data
   double minCelcius=DBL_MAX;           //To store min of Celsius data
   double avgCelcius=0;               //To store avg of Celsius data
   int count=0;
  
  
   while (fscanf(fp, "%lf", &farenheitData) == 1) // expect 1 successful conversion
   {
       if (feof(fp))
       {  
           //break out when we reached reading till the end of file
           break;
       }
      
       double celsiusData = (farenheitData-32)/1.8;
      
       //Determining min, max and average
       if(maxCelcius<celsiusData){
           maxCelcius=celsiusData;
       }
      
       if(minCelcius>celsiusData){
           minCelcius=celsiusData;
       }
      
       avgCelcius+=celsiusData;
       count++;
      
       fprintf(fpOut,"%lf\n",celsiusData);
   }
  
   avgCelcius=avgCelcius/count;
          
   //Writing out the max, min and average of celsius data      
   fprintf(fpOut,"Max: %lf\n",maxCelcius);  
   fprintf(fpOut,"Min: %lf\n",minCelcius);  
   fprintf(fpOut,"Avg: %lf\n",avgCelcius);      
          
   //Closing resources     
   fclose(fp);
   fclose(fpOut);
   return 0;
}

Output=====================================================

Input File:

Output File:

Add a comment
Know the answer?
Add Answer to:
Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month...
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
  • 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...

  • Write a program that would ask the user to enter an input file name, and an...

    Write a program that would ask the user to enter an input file name, and an output file name. Then the program reads the content of the input file, and read the data in each line as a number (double). These numbers represent the temperatures degrees in Fahrenheit for each day. The program should convert the temperature degrees to Celsius and then writes the numbers to the output file, with the number of day added to the beginning of the...

  • Write a program named FahrenheitToCelsius that accepts a temperature in Fahrenheit from a user and converts...

    Write a program named FahrenheitToCelsius that accepts a temperature in Fahrenheit from a user and converts it to Celsius by subtracting 32 from the Fahrenheit value and multiplying the result by 5/9. Display both values to one decimal place. For example, if 88.5 degrees is input, the output would be: 88.5 F is 31.4 C Answer in C# (Posting incomplete code i have so far that wont run correctly.) using System; using static System.Console; class FahrenheitToCelsius { static void Main()...

  • Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...

    Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....

  • General overview This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin....

    General overview This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin. Your program will be reading in three double values. The first values are starting and ending temperatures. The third value is the increment value. There is no prompt for the input. There is an error message that can be displayed. This is discussed later. You need to display output for all of the values between the starting and ending values. First two values are...

  • java ASAP Assume that you have tracked daily minutes of you work out for a week....

    java ASAP Assume that you have tracked daily minutes of you work out for a week. Save the following data into a text file in a notepad. 50 10 36 11 47 30 Write a java program that reads the minutes for a week from the text file that you created. Read the minutes from the input file into the array in one execution of the program.write a java method to find out the maximum and minimum values. Your program...

  • (By using HCS12 assembly)You have a table of 10 Fahrenheit temperatures stored as words in Flash....

    (By using HCS12 assembly)You have a table of 10 Fahrenheit temperatures stored as words in Flash. Use the posted lab1_b.asm file as starting point. Write an assembly program that converts every Fahrenheit temperature element in Fahrs array into a Celsius temperature and stores the result at the corresponding element in Cels array. Use this relation: C = (5/ 9) * (F 32) for conversion. Because temperatures are signed, you will have to use signed multiplication and division instructions in your...

  • Write a program in C++ that gives the temperature of earth at a depth. It must...

    Write a program in C++ that gives the temperature of earth at a depth. It must be in C++ and follow the information below: Problem description Write a program to take a depth in kilometers inside the earth as input data; calculate and display the temperature at this depth in both degrees Celsius and degree Fahrenheit. The formulas are: Celsius temperature at depth in km: celsius = 10 x depth(km) + 20 Convert celsius to fahrenheit: fahrenheit = 1.8 x...

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

  • Please Read it all and carefully In visual basic(vba)do the following program Summary INGE Industry, Inc....

    Please Read it all and carefully In visual basic(vba)do the following program Summary INGE Industry, Inc. needs a program in which the date and temperature in Celsius degrees of an industry laboratory are recorded and stored in a sequential file. In addition, you can see the recorded data and convert the temperatures in the following units: Fahrenheit, Kelvin and Rankine. In addition, they want to see a linear graph that reflects how the temperature has fluctuated day by day, for...

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