Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

How do our biological rhythms impact daily functioningpg18

Answered: 1 week ago

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago