Question: i'm using xcode since i have a mac and its saying build succeeded and asks me me to enter input file name, and i saved

i'm using xcode since i have a mac and its saying build succeeded and asks me me to enter input file name, and i saved the numbers above on my desktop as "input" its an rtf file and when i enter input.rtf or input it says file does not exist

instructions:

You changed your mind about how to read the temperature measurements for your home weather station. Instead of reading them directly from a sensor every hour, you have decided to have the measurement instrument build a daily file with 25 entries. Each entry contains the temperature in degrees F at the top of each hour nothing else. The first reading corresponds to midnight, the second to 1 AM, and so on. Then, in addition to writing the input columns and the calculated output (max, min and average temperatures) to the screen (as done for HW #4), your program will also write the same output to a file a different one than the one containing the hourly temperatures.

So, take the program you wrote for HW #4 and modify it to do the above. A text file called input-temps.txt has been posted to the miscellaneous postings page in Webcourses that contains 25 temperature values to be read for each day. Your program should read those values and save them to an array. When finished calculating the max, min and avg, it should write those values, along with the hourly temperature table, to an output file that you will call output-temps.txt. Therefore, do the following:

1) Delete the get_values() function in your existing code. You will no longer need it.

2) In its place, define a read_temps() function that will ask the user the name of the file to be read, reads that file, and saves the read values to an array.

3) The calc_values() function you already have should be called from main(). Then main() needs to pass the hourly temperature array to calc_values() by reference. In addition to calculating the max, min and avg as it did for HW #4, it will write those values to the output-temps.txt external file. The contents of the output external file should be formatted in the same manner as in the output to screen.

You should submit the source code as usual. Do not submit the output-temps.txt external file as written by the program. The program should do that when it is executed during grading.

These are the numbers for input-temps.txt :

7

67

69

71 77 79 80 80 82 85 87 88 91 93 94 95 95 96 94 90 85 82 81 77 74 

This is what i got, i'm using xcode since i have a mac and its saying build succeeded and asks me me to enter input file name, and i saved the numbers above on my desktop as "input" its an rtf file and when i enter input.rtf or input it says file does not exist

//temperature.c

#include

#include

//function prototype

void calc_results(int time[], int size);

void read_temps(int temp[]);

//set size of array as global value

#define SIZE 25

int main ()

{

rand();

//Declare temperature array with size 25 since we are going from 0 to 24

int i, temp[SIZE];

read_temps(temp);

//Temperature for the day of October 14, 2015

printf("Temperature conditions on October 14, 2015: ");

printf(" Time of day\tTemperature in degrees F ");

for (i = 0; i < SIZE; i++)

printf( "%d \t\t%d ",i,temp[i]);

//call the metod calc_results(temp, SIZE);

calc_results(temp, SIZE);

//pause the program output on console until user enters a key

system ("PAUSE"); return 0;

}

/**The method read_temps that takes the input array temp

and prompt user to enter the name of the input file

"input.txt" and then reads the tempertures from the file

for 24 hours of day */

void read_temps(int temp[])

{

char fileName[50];

int temperature;

int counter=0;

printf("Enter input file name : ");

//prompt for file name

scanf("%s",fileName);

//open the input file

FILE *fp=fopen(fileName, "r");

//check if file exists or not

if(!fp)

{

printf("File doesnot exist. ");

system ("PAUSE"); //if not exit, close the program

exit(0);

}

//read temperatures from the file input.txt until end of file is encountered

while(fscanf(fp,"%d",&temperature)!=EOF)

{

//store the values in the temp array

temp[counter]=temperature;

//incremnt the coutner by one

counter++;

}

//close the input file stream fp

fclose(fp);

}

void calc_results(int temp[], int size)

{

int i, min, max, sum = 0;

float avg;

min = temp[0];

max = temp[0];

//Loop that calculates min,max, sum of array

for (i = 0; i < size; i++)

{

if (temp[i] < min)

{

min = temp[i];

}

if (temp[i] > max)

{

max = temp[i];

}

sum = sum + temp[i];

}

avg = (float) sum / size;

//open an external output file

FILE *fout=fopen("output.txt","w");

//Temperature for the day of October 14, 2015

fprintf(fout,"Temperature conditions on October 14, 2015: ");

fprintf(fout," Time of day\tTemperature in degrees F ");

//write time of day and temperature

for (i = 0; i < SIZE; i++)

{

fprintf( fout,"%d \t\t%d ",i,temp[i]);

}

printf(" Min Temperature for the day is : %d ", min);

printf("Max Temperature for the day is :%d ", max);

printf("Average Temperature for the day is : %f ", avg);

//write min ,max and avg to the file "output.txt"

fprintf(fout," Min Temperature for the day is : %d ", min);

fprintf(fout,"Max Temperature for the day is :%d ", max);

fprintf(fout,"Average Temperature for the day is : %f ", avg);

//close the output file stream

fclose(fout);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!