Question
Task 2 Task 2.1 Write a struct whose purpose is to store daily temperature sensor readings. Call it Reading . It will contain the following
Task 2
Task 2.1
Write a struct whose purpose is to store daily temperature sensor readings. Call it Reading. It will contain the following data members:
day - an integer representing the day number of the reading high - a double representing the high temperature reading on the given day
low- a double representing the low temperature reading on the given day
Task 2.2
Overload the ostream operator << to accept a Reading as an argument such that when I write the following.
Reading r; r.day = 1; r.high = 100;
r.low = 0; cout << r << endl ;
Then the following will be printed to the screen.
{ ( Day: 1 ) ( High: 100 ) ( Low: 0 ) }
Furthermore, our sensor readings may be missing some or all of its temperature data. Let a high/low value of -1 denote a missing value. If a missing value is present, then omit output for the data in question. For example:
Reading r; r.day = 50;
r.high = -1;
r.low = 20.0;
cout << r << endl;
Would give us
{ ( Day: 50 ) ( Low: 20 ) }
Task 2.3
Overload the istream operator >> to accept a Reading as an argument. We want to be able to read data of the form
{(Day: ## )(Low: ## )(High: ## )}
For example, given the following code and user input:
CODE:
Reading r;
cin >> r;
TERMINAL INPUT:
{ ( Day: 25 ) ( Low: 5 ) ( High: 50 ) }
Would populate our reading r with r.day = 25, r.low = 5, and r.high = 50 . Additionally, you must handle possible input with missing low/high values. For example it should be able to handle an input of
{ ( Day: 25 ) ( High: 50 ) } OR { ( Day: 25 ) ( Low: 5 ) }
Task 2.4
Now that we have the ability to read/write Readings with << and >>, lets read a file containing Readings, readings.txt (listed at the end). Write a function called read_min_max. It will start by creating an empty vector (vector of readings). As we read the file one Reading at a time, we will add each reading to our vector.
After we have finished reading the file, find the Reading with the max high value and the Reading with the min low value and print those readings to the screen with cout.
Name your file task2.cpp
readings.txt:
{ ( Day: 1 ) ( High: 10 ) ( Low: 0 ) } { ( Day: 2 ) ( High: 20 ) ( Low: 5 ) } { ( Day: 2 ) ( High: 50 ) } { ( Day: 2 ) ( High: 100 ) ( Low: 22 ) } { ( Day: 2 ) ( Low: 50 ) } { ( Day: 2 ) ( High: 98 ) ( Low: 45 ) } { ( Day: 2 ) ( High: 80 ) ( Low: 60 ) } { ( Day: 2 ) } { ( Day: 2 ) ( High: 122 ) ( Low: 100 ) }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started