Question
Code in C++ In a new header file, create class Fahrenheit and class Celcius. Each class should store its temperature as a private member double.
Code in C++
In a new header file, create class Fahrenheit and class Celcius. Each class should store its temperature as a private member double. Each class should also have an accessor called getDegrees() which returns the temperature value as a double.
Give each class a constructor that takes the temperature value as a double and properly initializes the member value using an initialization list (no assignment in the constructor body).
Add logic to the class contructor bodies so that they ensure that the input values are within the freezing and boiling point of water, i.e. Celcius should enforce that the value is between 0.0 and 100.0 degrees. If the value is not in this range, terminate the program by throwing an exception.
Finally, give each class a second constructor that allows initialization from the other temperature type, i.e. Celcius(Fahrenheit f) and Fahrenheit(Celcius c). These should also set the member using the member initialization list and not in the constructor body. This will require to to forward declare one of your classes at the top of the file.
Implement the functionality in a separate source file. Write your own main function to test out your code and demonstrate that it is working correctly.
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