Write the program to read in a Fahrenheit temperature and display the status (H,
ID: 3539513 • Letter: W
Question
Write the program to read in a Fahrenheit temperature and
display the status (H, M, F, C). You are to this task by creating a class (.h) file that will consist of constructors that
initializes and accepts the Fahrenheit value, a Mutator that will get the score and an Accessor that will return the value,
declare a function that will be used to compute the status of the temperature entered.
Status
80 and above %u2013 H Hot
60 and above %u2013 W Warm
40 and above %u2013 F Fair
Below 40 %u2013 C Cold
The output should look like this.
Today temperature is 80 degrees Fahrenheit.
The weather code is H.
Explanation / Answer
faren.h
#include <iostream>
using namespace std;
class faren
{
double fn;
public:
faren()
{
fn=0.0;
}
faren(double x)
{
fn=x;
}
char mutator()
{
if(fn>=80)
return 'H';
else if(fn>=60)
return 'M';
else if(fn>=40)
return 'F';
else
return 'C';
}
double accessor()
{
return fn;
}
};
main.cpp
#include <iostream>
# include "faren.h"
using namespace std;
int main()
{
faren obj;
double f;
cout<<"Enter temperature in Farenheit"<<endl;
cin>>f;
obj = faren(f);
cout<<"Today temperature is "<< obj.accessor()<<" farenheit"<<endl;
cout<<"The whether code is "<<obj.mutator()<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.