Question: Answer the questions about the Temperature class definition shown below: class Temperature { public: Temperature ( ); // POST: object has 0 C void setTemp
Answer the questions about the Temperature class definition shown below:
class Temperature {
public:
Temperature ( ); // POST: object has 0 C
void setTemp (double value); // POST: set the Celsius temperature
double getTemp ( ); // POST: return the Celsius temperature
double convert ( ); // POST: return the Fahrenheit equivalent
bool operator == (Temperature other);
// POST: return true if object and other have the same temp
private:
double temp; // temperature stored in Celsius units
};
1. Which function is known as the constructor?
a. Temperature b. setTemp
c. getTemp d. operator==
2. Which function is known as a modifier function?
a. Temperature b. setTemp
c. getTemp d. operator==
3. The user attempts the following code but it does not compile. Explain the problem.
Temperature winter;
winter.temp = 16.5;
__________________________________________________________________________
4. Write the code to assign the temperature 37 C to a Temperature object named day.
__________________________________________________________________________
5. What statement is true about the private data of object day after the user code below?
Temperature day;
a. Data member temp stores 0
b. Data member temp contains an undefined value.
c. Data member temp stores whatever value the user specifies
6. Write the code to display to the screen the Fahrenheit temperature stored in a Temperature object named day.
__________________________________________________________________________
7. Which user code correctly compares Temperature objects named one and two. If they are the same display word OK.
a. if (one.getTemp( ) == two.getTemp( ) ) cout << OK;
b. if (one == two) cout OK;
c. if (one.temp == two.temp) cout << OK;
d. Both choices a) and b) are correct.
e. All choices a), b), and c) are correct.
8. In most classes the data is stored in the _______________ section and the functions are stored in the ________________ section within the class definition.
a. public, private
b. private, public
c. header, source code
d. specification, implementation
9. Assume class Temperature is divided into files Temperature.h and Temperature.cpp files. An application is written that needs to use a Temperature object. Which statement should be included at the top of the program?
a. #include
b. #include Temperature.h
c. #include Temperature.cpp
d. #include
10. Which declaration causes the constructor function to be executed?
a. Temperature daily;
b. Temperature today ( );
c. Temperature monday = 0;
d. Temperature winter = Temperature ( );
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
