Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that will collect from the user a list of temperature samples taken throughout asingle day. Each temperature sample consists of a temperature

Write a program that will collect from the user a list of temperature samples taken throughout asingle day. Each temperature sample consists of a temperature (degrees Fahrenheit) and a time(military time in hours and minutes only). The hours in military time is an integer between 0 and23 and the minutes is an integer between 0 and 59. Your program will display military time inthe format HH:MM, where HH is the hour and MM is the minutes. For example, midnight is00:00 in military time, noon is 12:00, 9:10am in standard time is 09:10 in military time, and 3:15pm in standard time is 15:15 in military time.

The procedure main() (see the code template temps_template.cpp) has been written foryou (DO NOT change anything in the main() procedure) as well as the members (attributes andfunctions) of the Classes Miltime and Fahrenheit. You will write code for the member functions of both classes and also helper functions as indicated by the comments /* INSERTCODE HERE */.Run temps_solution.exe to see an example of the program. A sample run of the program would look like this (bold indicates what the user will enter):

> temps.exe Enter the output file name: out.txtEnter the number of samples: 2 Enter degrees(Fahrenheit): 212

Enter hourse: 13

Enter minutes: 27

Enter degrees(Fahrenheit): 32.5

Enter hours: 1

Enter minutes: 12

> cat out.txt

-------------------------------------------------------------------------------------------------

Sample #1: 212 degrees F (or 100 degrees C ) at 13:27

Sample #2: 32.5 degrees F (or 0.277778 degrees C ) at 1:12

------------------------------------------------------------------------------------------------

The average temp is 122.25 degrees F

The coldest temp is 32.5 degrees F

The last sample was taken at time 13:27 To view the contents of the file, type cat out.txt. Your program must work for any file names besides out.txt.

1. The function prototypes are provided for you and must NOT be changed in any way.

2. The procedure main() is provided for you and must NOT be changed in any way.

3. Understand the class definitions for MilTime and Fahrenheit.

4. Understand the algorithm in the procedure main().

5. Do NOT add more functions/procedures to the solution.

6. Each function should have a comment explaining what it does.

7. Each function parameter should have a comment explaining the parameter.

8. Write code by replacing every place /* INSERT CODE HERE */ appears with your solution.

9. Implement the member functions for the class MilTime. Use the appropriate class attributesof the class MilTime in your solution. Use the provided class attributes in your solution of the class MilTime.10. The member function write_out() of the class MilTime writes the military time in the formatHH:MM to a given file output stream. Write code to ensure this format.11. You may assume that the user will enter only valid values for hours (0-23) and minutes (0-59).12. Implement the member functions for the class Fahrenheit. Use the appropriate classattributes of the class Fahrenheit in your solution.

Use the provided class attributes in your solution of the class MilTime. Include the C++ command #include to use the C++ exit command. CLOSE the file stream. (Note: You will lose points if you forget to close the outputfile stream, even though your program runs correctly). Important note, do not write redundant code.

13. The member function getTemp() of the class Fahrenheit retrieves the degrees stored inFahrenheit.

14. The member function getTime() of the class Fahrenheit retrieves the military time (anobject).

15. The member function getCelsius() of the class Fahrenheit converts the stored degrees inFahrenheit to Celsius and returns this conversion.

16. The member function write_out() of the class Fahrenheit writes a list of the samples andother information to an output file given a file name. Use the file name to open the file for output. Make sure to pass a C style string, not the C++ string, to the open routine. Be sure to use the type ofstream, not ifstream, for your output file streams. Check if the file was successfully opened for output. If not, print an error message (see sample executable) and exit. 17. These functions are called from the main() function.

Implement the function read_filename() that prompts, reads, and returns a file nameas a string. Include the C++ command #include to use C++ strings. Implement the function read_num_samples() that prompts and reads the number oftemperature samples (degree and time) that the user will enter. Implement the function read_samples() that prompts the user for a single temperatesample and then returns a newly constructed object. Implement the function write_to_file() that display all output to the output file. Thisfunction must call the following functions in order to receive full credit:o Implement the function average_temp() that computes the average

temperature over all of the samples.o Implement the function coldest_temp() that returns the lowest temperaturevalue over all of the samples.

o Implement the function last_sample() that returns the last temperaturesample taken during the day.

PLEASE FOLLOW THIS TEMPLATE:

#include #include #include #include #include #include

using namespace std;

class MilTime { private: int hour; int minutes;

public: int getHour() const; int getMin() const; void setHour(const int h); void setMin(const int m); void write_out(ofstream & fout); };

class Fahrenheit { private: double degree; MilTime time;

public: // member functions double getTemp() const; MilTime getTime() const; double getCelsius() const; void setTemp(const double temp); void setTime(const int h, const int m); void write_out(const string fname) const; };

// FUNCTION PROTOTYPES GO HERE: string read_filename(const string prompt); int read_num_samples(const string prompt); Fahrenheit read_sample(const int k); void write_to_file(const string filename, const vector & samples); double average_temp(const vector samples); double coldest_temp(const vector samples); MilTime last_sample(const vector samples);

int main() { // Define local variables string fname; // Output file name int n; // Number of temperature samples vector temps; // Temperature samples // Prompt for the name of the output file to write fname = read_filename("Enter the output file name: "); // Prompt for the number of temperature samples n = read_num_samples("Enter the number of samples: "); // Read temperature samples from user for (int i = 0; i < n; i++) { cout << endl; temps.push_back(read_sample(i + 1)); } // Write the sample information to the outputfile write_to_file(fname, temps); cout << endl; return 0; } // FUNCTION DEFINITIONS GO HERE: // CLASS MEMBER FUNCTION DEFINITINOS GO HERE: int MilTime::getHour() const { /* INSERT YOUR CODE */ }

int MilTime::getMin() const { /* INSERT YOUR CODE */ }

void MilTime::setHour(const int h) { /* INSERT YOUR CODE */ }

void MilTime::setMin(const int m) { /* INSERT YOUR CODE */ }

void MilTime::write_out(ofstream & fout) { /* INSERT YOUR CODE */ }

double Fahrenheit::getTemp() const { /* INSERT YOUR CODE */ }

MilTime Fahrenheit::getTime() const { /* INSERT YOUR CODE */ }

double Fahrenheit::getCelsius() const { /* INSERT YOUR CODE */ } void Fahrenheit::setTemp(const double temp) { /* INSERT YOUR CODE */ }

void Fahrenheit::setTime(const int h, const int m) { /* INSERT YOUR CODE */ }

string read_filename(const string prompt) { /* INSERT YOUR CODE */ }

int read_num_samples(const string prompt) { /* INSERT YOUR CODE */ }

Fahrenheit read_sample(const int k) { /* INSERT YOUR CODE */ }

void write_to_file(const string filename, const vector & samples) { /* INSERT YOUR CODE */ }

double coldest_temp(const vector samples) { /* INSERT YOUR CODE */ }

MilTime last_sample(const vector samples) { /* INSERT YOUR CODE */ }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

Compute FMSb/MSw using your calculator.

Answered: 1 week ago