Write an inline function that will take as input the Fahrenheit temperature and
ID: 3764068 • Letter: W
Question
Write an inline function that will take as input the Fahrenheit temperature and output the Centigrade temperature Write a script file that will call the function file developed in (i) above and using appropriate commands such as 'disp' or 'fprintf display the results on the screen as: Fahrenheit = XXXI Kelvin = XXX2 Rankine = XXX3 Where XXXI, XXX2 and XXX3 correspond to the values returned from the output arguments of the function file developed above. Comment your function file and script file appropriately for lucidity.Explanation / Answer
Solution:
-----------------------------------
#include <iostream>
using namespace std;
//This class converts temperature from one scale to another
class TemperatureScaleConverter
{
private:
float centigrade; //temperature in centigrade
float fahrenheit; //temperature in fahrenheit
float kelvin; //temperature in kelvin
float rankine; //temperature in rankine
public:
//constructor
TemperatureScaleConverter()
{
centigrade=0.0;
fahrenheit=0.0;
kelvin=0.0;
rankine=0.0;
}
//getter and setter functions
float getCentigrade() const {
return centigrade;
}
void setCentigrade(float centigrade) {
this->centigrade = centigrade;
}
float getFahrenheit() const {
return fahrenheit;
}
void setFahrenheit(float fahrenheit) {
this->fahrenheit = fahrenheit;
}
float getKelvin() const {
return kelvin;
}
void setKelvin(float kelvin) {
this->kelvin = kelvin;
}
float getRankine() const {
return rankine;
}
void setRankine(float rankine) {
this->rankine = rankine;
}
//conversion functions
float FahrenheitToCentigrade(float fahren_temp)
{
return ((fahren_temp-32)/1.8);
}
float FahrenheitToKelvin(float fahren_temp)
{
return ((fahren_temp+459.67)/1.8);
}
float FahrenheitToRankine(float fahren_temp)
{
return (fahren_temp+459.67);
}
//output functions
void disp()
{
cout<<"Centigrade="<<getCentigrade()<<endl;
cout<<"Fahrenheit="<<getFahrenheit()<<endl;
cout<<"Kelvin="<<getKelvin()<<endl;
cout<<"Rankine="<<getRankine()<<endl;
}
};
//main function
int main() {
TemperatureScaleConverter tsc;
tsc.setFahrenheit(18.0);
tsc.setCentigrade(tsc.FahrenheitToCentigrade(tsc.getFahrenheit()));
tsc.setKelvin(tsc.FahrenheitToKelvin(tsc.getFahrenheit()));
tsc.setRankine(tsc.FahrenheitToRankine(tsc.getFahrenheit()));
tsc.disp();
}
------------------------
Note: Image uploaded by you does not show the overall question neither mentions the language to be used to develop the program. So, have used C++ to demonstrate how to convert temperature from scale to another. You can convert accordingly if using language other than C++, logic will remain the same.
Inline functions are those which are defined inside the class.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.