Answer to Question #325348 in C++ for Safaah

Question #325348

Define two classes Fahrenheit and celsius to represent temperature in Fahrenheit and celsius respectively.Use conversion function to convert from one system to the other


1
Expert's answer
2022-04-07T08:42:18-0400
#include <iostream>
#include <string>

using namespace std;

class Fahrenheit
{
	float Fvalue;
public:
	Fahrenheit(float _Fvalue):Fvalue(_Fvalue){}
	float GetValue() const{ return Fvalue; }
	void Display()
	{
		cout << "\nValue is " << Fvalue << " Fahrenheit";
	}
};


class Celsius
{
	float Cvalue;
public:
	Celsius(float _Cvalue):Cvalue(_Cvalue){}
	float GetValue()const { return Cvalue; }
	void Display()
	{
		cout << "\nValue is " << Cvalue << " Celsius";
	}
};

Celsius Convert(const Fahrenheit& f)
{
	float a = (f.GetValue() - 32) * 5 / 9;
	return Celsius(a);
}


Fahrenheit Convert(const Celsius& c)
{
	float a = (c.GetValue() *9 )/ 5 + 32;
	return Fahrenheit(a);
}

int main()
{
	
	Fahrenheit f(100);
	f.Display();
	Celsius c = Convert(f);
	cout << "\nis equal to ";
	c.Display();
	cout << endl;
	Celsius cl(50);
	cl.Display();
	cout << "\nis equal to ";
	Fahrenheit fr = Convert(cl);
	fr.Display();
}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS