 Temperature Program Using C++

Subject Computer Science C-Family Programming

Question

A file gives all of the temperatures for a period of time. Each number in the file is the temperature for 1 day. The number of days could be a month, a year, or the duration of a trip. You are to read in all of the temperatures from the file and print the following statistics:

The number of days
The temperature range, example: The temperatures ranged from -5 to 45
The average temperature
The number of days (if any) that were freezing (32 degrees or less). Don't print if 0!
The number of days (if any) that were 100 degrees or more. Don't print if 0!
Example 1:
The file contains these numbers:
20
15
32
40
37
Output:
There were 5 days.
The temperatures ranged from 15 to 40.
The average temperature was 28.8
It was freezing on 3 days.
Example 2:
The file contains these numbers:
85
90
95
100
102
70
80
90
Output:
There were 8 days.
The temperatures ranged from 70 to 102.
The average temperature was 89.
It was 100 degrees or more on 2 days.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
ifstream inFile;
char data;
int count = 0, min, max, total = 0, freezing = 0, hot = 0;
double average;
inFile.open("input.txt", ifstream::in);

while(!inFile.eof())
{
inFile.getline(data, 5);
int num = atoi(data);
if(count == 0 || max < num)
max = num;
if(count == 0 || min > num)
min = num;
if(num <= 32)...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

The Simplistic Primary Predictor in C++ \$20.00
Computer Science
Programming
C++
Primary Predictor
Election Results
Factors
Candidates
States
Information
Commercials
Campaign
Calculations
Statements
Variables
Input
Output
Shapes Program in C++ \$30.00
Programming
C++
Shapes
Codes
Metric Conversions
Mathematics
Functions
Area
Centimeters
Kilos
Points
Celsius
Fahrenheit
Circle
Square
Rectangle
Display Choices
Side Lengths
Input
Output
Data Structures & Algorithms in C++ \$10.00
Computer Science
Programming
Data Structures
C++
Algorithms
AVL Trees
Rotation
Traversal
Input
Output
Characters
Lines
Keys
Operations
Statements
Variables
Night Club Management Program \$25.00
Programming
Computer Science
Night Clubs
Management
Waiters
Bartenders
Orders
Employees
Work
Customers
Prices
Tips
Statements
Variables
Objects
Data
Parallel Arrays
System