Write a flowchart that reads an input file that contains two fields from any num
ID: 3864732 • Letter: W
Question
Write a flowchart that reads an input file that contains two fields from any number of records.(Could be thousands!) The first field contains a number from 1-7. 1 represents Monday, 2 - Tuesday and so forth thru 7 with represent Sunday. The second field on each record will be a temperature for that day of the week. (There will be multiple records for each day of the week and can be in any order in the input file.)
Example of fields names for each record of the input file;
DOW TEMP These names are not in the file!
Example of possible records from input file;
1 62
2 54
7 55
6 77
1 55
continues on with any amount of records....could be a few or thousands!
Assume that all input records will contain valid information.
Temps could be negative.
YOU CAN ONLY READ THROUGH THE FILE ONCE!
Your program will find the High, Low and Average Temperature for each day of the week. Then it should write out a new record to an output file for each day of the week. (The output file will only contain 7 records. One for each day of the week.) Each output record will contain these fields;DOW, HighTemp, LowTemp, AverageTemp. (These are field names and not in the file.) Also include in your program status output displays to the screen to indicate when the program has started and ended. Example:
DOW Temperature Started. Please wait....
DOW Temperature Completed Successfully.
Example of fields names contained in each record;
DOW HIGH LOW AVERAGE
(These are not in the file!)
Example of possible values that might be contained in an output record;
1 78 66 70
2 87 77 81
3 70 80 75
4 0 0 0
Etc....
The output file MUST contain 7 records. One record for each day of the week! Put 0 for the high, low and average if no records were found in the input file for that day of the week.
Explanation / Answer
Step 1: declare 4 arrays of size 7 each and also initialize them accordingly:
int Sum[7] //initialize them to 0
int Count[7] //initialize them to 0
int Min[7] //initialize them to max possible values
int Max[7] //initialize them to min possible values
Step 2: Open the file
Step 3: For each line of the file till EoF (End of File)
Step 4: Read the first data, let it be day
Read the second data, let it be temp
Step 5: Increment the dayth element of sum array by 1 //Count[day]++
Step 6: Add temp to the dayth element of sum array //Sum[day] = Sum[day] + temp
Step 7: Check if the dayth element of min array is more than temp, if so
store temp in dayth element of min array.
Step 8: Check if the dayth element of max array is less than temp, if so
store temp in dayth element of max array.
Step 9: If EoF is not reached, go to step 3, else close the file and goto Step 10
Step 10: Min and Max array contains the min and max temp recorded for each of the 7 days
Step 11: Divide each element of the Sum array by the corresponding Count // Sum[i] = Sum[i]/count[i] 1 <= 0 <= 7
Step 12: Sum array now contains the average temp recorded for each of the 7 days
Step 13: Write all data to output file.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.