Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1: Create a Class Temperature: o Private data members: 1. degree (of dou

ID: 3549277 • Letter: P

Question

                    Problem 1:                 

                    Create a Class Temperature:                 


o Private data members:                 


1. degree (of double                    type)                 


2. Scale (of char                    type)                 


o Supply the following methods                 


o Temperature(); -- Constructor to set default value of degree                    and                 

                    scale                 


o double getDegree(); -- This method returns the degree.                 


o char getScale();--                    This method returns the scale.                 


o void set(double newd, char news);-- This method sets the                 

                    current values of the data members (degree and scale) to new                 

                    values passed by the parameters. This function returns nothing.                 


o void convert(char new_s); -- This method converts the degree of                 

                    the current/this temperature to the equivalent measured in the                 

                    parameter scale (if necessary).                 


o void print(); --                    This method prints this temperature in the form                 

                    "xx.x F" or "xxx.x C" to cout.                 

Problem 2                 

                    Using the Temperature class you wrote above, write a program which                 


1. Create two Temperature objects.                 


2. Ask the user for two temperatures and set the values in each                    object                 

                    appropriately.                 


3. Print both objects to the terminal.                 


4. Checks to see if the two temperatures are equivalent. If so, print to                    the                 

                    terminal "Equivalent" or "Not equivalent" otherwise.

Explanation / Answer

Dear,


#include <iostream>
using namespace std;
#include <cassert>

class Temperature
{
public:
Temperature();
Temperature(double degrees, char scale);
void print() const;
double getDegrees();
char getScale();
double covert(char N_Scale);
bool compare(Temperature t);

private:
double Degrees;
char Scale;
};
Temperature::Temperature(double degrees,char scale)
{
//assert(scale == 'F' || scale == 'C');
Degrees = degrees;
Scale = scale;
}

//-- Definition of default constructor
Temperature::Temperature()
{
Degrees = 0;
Scale = 'C';
}
char Temperature::getScale()
{
    return Scale;
}
double Temperature::getDegrees()
{
    return Degrees;
}
void Temperature::print() const
{
cout<< Degrees << ' ' << Scale;
}
double Temperature::covert(char N_Scale)
{
    if(N_Scale=='C')
       return Degrees;
    else if(N_Scale== 'F')
      return (Degrees - 32)/1.8;
    else
      cerr << " Invalid scale: " <<endl;
    return 0;
}
bool Temperature:: compare(Temperature obj)
{
    if(Degrees==obj.getDegrees()&&Scale==obj.getScale())
        return true;
    else
        return false;
}
//#include "Temperature.h"

int main()
{
    //Declare objects of class
Temperature temp1;
Temperature temp2(98.6, 'C');

temp1.print(); // displays 0 C
cout << endl;
temp2.print(); // displays 98.6 F
cout << endl;
cout<<"Converted:"<<temp2.covert('F')<<endl;
cout<<"Comparing two:"<<temp1.compare(temp2)<<endl;

//pause system for a while
system("pause");
}