Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Temperature as a Class Assignment The goal of this assignment is to better acquaint you with using an object in the design of a solution.

Temperature as a Class Assignment The goal of this assignment is to better acquaint you with using an object in the design of a solution. Your task is to create an application that asks the user to enter a temperature and the type of units of that temperature. It then reports the temperature in 3 different units. The application should use a class called Temperature that stores a single temperature, but provides functions to set and get that temperature using any of the three units: Celsius, Fahrenheit, or Kelvin. In the code for getTemperatureFromUser, given below, you can see the three set functions being used. Your job is to implement the Temperature class, and then write a main function that uses the three get functions to complete this task. I have included a separate function prototype(not part of the Temperature class), called getTemperatureFromUser(), that takes a pointer to a Temperature object as its argument. Put this function in the same file where you put main(). The getTemperatureFromUser function prompts the user for the temperature and the type of units and reads them in. It also detects if the user gives bad input and provides the user with an opportunity to try again. When the getTemperatureFromUser function returns, the temperature object which was passed as a pointer argument should contain a temperature. In your main function, call the getTemperatureFromUser function, and then, using the three get functions of the temperature object, report the temperature in each of the three units. If written correctly, the output should look exactly as shown in the console window shown below.

image text in transcribed

Please read the following scenario to make sure you understand what is meant by an abstract temperature. Imagine this scenario. I give my Temperature object to John to take the temperature. He is comfortable using Fahrenheit and his thermometer reads in Fahrenheit. So he sets the temperature in Fahrenheit. Then I give the same Temperature object to Helga. Helga is accustomed to Celsius, and her lab equipment uses Celsius. So she uses the getCelsius to get the temperature that John just measured. In addition, she wants to compute something that involves the temperature, but the formula she has is written to use Kelvin. So she gets the same temperature for her formula, but this time she gets it in Kelvin. Now supposing the formula tells her that the temperature they want is a little different, but they only have it in Kelvin. So she sets that temperature in Kelvin and sends it back to John. John looks at what that is in Fahrenheit so he can work on getting the right temperature. The point is that the object is THE TEMPERATURE and having a Temperature object makes it possible for anybody to see THE TEMPERATURE without having to know anything about who set it or how they set it. We call that an ABSTRACTION. It gives us what we need, while hiding unnecessary details from those who use it. Yes, there is conversion involved. But that is just part of the job of hiding the detail of which units are used inside the class for storage. In other words, there is no "convert" function. Conversion is just what we may or may not to do in a get or set in order to make it work as an abstraction.

. For the Temperature class, you have to decide which type of units to use for the private storage, and then provide getters and setters with conversions to and from that value for the other choices. In this case, because the conversions are well known, you dont need to use constants. You can find the conversion formulas by Googling them (e.g. formula for fahrenheit to celsius conversion).

// Function: getTemperatureFromUser

// Purpose: Prompt user for a temperature and put it in the argument object

// Parameter: temperatureObject is a pointer to a Temperature object

// Returns: nothing

// void getTemperatureFromUser(Temperature* temperatureObject)

Develop this function onto the end of your main file (the one where you have main()). Then add a prototype to the beginning of the file so you can call it from main. In your main, declare an object of your Temperature class, call getTemperatureFromUser with a pointer to your object, and then write three lines with cout to output the lines shown in the console output above.

C.Windows system32\cmd.exe will ask you for a temperature and its units For example, your input might be "98.6 F" Use C for Celsius, F for Fahrenheit, K for Kelvin. naertemperatureure followed i sw3.units: ? K hat temperature in Rahrenheito1 5 -459.67 hat temperature in Celsius is-273 Press any key to cont inue _

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

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions