Objective  Exercise using ifstream and ofsteam objects to read and write to files.  Exercise using loops. Counting, accumulation, relational expressions  Exercise handling file open errors. ...

Objective
 Exercise using ifstream and ofsteam objects to read and write to files.
 Exercise using loops. Counting, accumulation, relational expressions
 Exercise handling file open errors.
 Exercise detecting end of file input.
 Error handing logic to accept valid inputs.
Lab Assignment #7.1 - Process Temperatures

Write a program that opens a file containing temperatures. The program will read all the temperatures

in the file and stop reading when end of file is reached. While reading the temperatures, the program

will determine:
 the lowest temperature and date of temperature,

 the highest temperature and date of temperature,

 the number of temperatures read from file, and

 the average temperature.

At the conclusion of the program, it will write the following to an output file:
 the name of the input file processed,

 the lowest temperature and date of temperature,

 highest temperature and date of temperature,

 number of temperatures read from file, and

 average temperature to an output file.

The program will also write a message to the console:Rowan University Assessment Page 2 of 4
 a success message indicating the file has been processed and

 the name of the output file where results are written.
Input File Format
In order to read the input from a file, the program needs to know the format of the file. Every line in the

file is formatted exactly the same, with each column meaning same thing. Each row in the file has 4

unique values. The Format of the file is:
The file has 4 columns of data delimited with white space.
 First value, Month is an integer 1-12.
 Second value, Day is an integer from 1-31.
 Third value, Year is an integer.
 Fourth value, Temperature is a positive or negative decimal value.
 showing this is end of the line.
Program Flow
 Display purpose of program to console.
 Prompt user for the input file name containing temperatures. Use the input file provided

containing temperature data (TempData1.txt, TempData2.txt, ...TempData6.txt) These are

found on Canvas for you to download.
 Prompt user for the output file name where results will be written. Enter your own filename

and remember the name.
 Error handling: If the input file cannot be opened, do NOT process file and Do Not write to

output file. Only print an error to the Console. Indicate which file was not opened

successfully.

o DO NOT USE return, break, goto, continue, or exit to terminate

the program or loops. Organize conditional expressions to skip code to process file.
 If BOTH files can be opened, then proceed.
 Read the data from the Temperature Data files provided.

 As the values are read from the file, gather data to determine the:
o lowest temperature and date of the temperature,

o highest temperature and date of the temperature,

o the number of temperatures, and

o average of all temperatures (remember how to calculate average?).
 After ALL numbers are read from file:
o Write to the output file the:

 input file name,

 highest temperature and date of the temperature,

 lowest temperature and date of the temperature,

Month Day Year Temp
Month Day Year Temp
Month Day Year TempRowan University Assessment Page 3 of 4
 the number of temperatures read from file, and

 average values.

o Write to the Console:
 A message that input file was processed Successfully.
 The name of the output file where results are written.
 Note: I know we did not get there yet, but the use of arrays or vectors is prohibited for this

exercise. We learned the tools needed for the program.
 Note: The use of INT_MIN/FLT_MIN and INT_MAX/FLT_MAX are prohibited for this exercise.

Don’t create artificially large or small numbers. We learned the tools needed for the

program. Think of another logic flow to determine lowest and highest value as program

reads 1 temperature at a time.
Input Files containing Temperatures
I provided multiple Temperature files. This is so you can run different tests containing different test

data to validate your program. Files are:
 TempData1.txt
 TempData2.txt
 TempData3.txt
 TempData4.txt
 TempData5.txt
 TempData6.txt
Output File Format as Follows
 The name of the input file processed.
 The Lowest, Highest, and Average Temperatures are rounded to 1 decimal place.
 Align decimal places
 Write the Month#, Day#, and Year of the Low and High temperatures.
 Format output using manipulators as follows:
EXAMPLE: Successful File output should look like this (For TempData1.txt):
Input File name processed: TempData1.txt
Number of temperatures: 383
Lowest temperature: -8.0 on 2/6/2014
Highest temperature: 82.2 on 7/6/2014
Average temperature: 49.6
Input File name processed:

Number of temperatures: ####
Lowest temperature: ###.# on M/D/YYYY
Highest temperature: ###.# on M/D/YYYY
Average temperature: ###.#Rowan University Assessment Page 4 of 4
Console Output Format as Follows
 When Successfully opening BOTH files, we will write a successful message with the input and

output file names to the console.
 When either of the files cannot be opened, we display an error message to the console with the

filename that could not be opened.
EXAMPLE: Successful Example when BOTH input and output file names can be opened. User input

notated with Bold RED font.
Error Case Example, Invalid input File name: What happens when user enters incorrect input file name.

User input notated with Bold RED font. NOTE: No Output File is written to.

END.
Mar 25, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here