Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ program for Celsius to Fahrenheit and Fahrenheit to Celsius conversion using class

/* Write a C++ Program to design a class Temperature
with two float variables fahren and celsius
and a member function 'conversion' to convert 
fahrenheit into celsius
*/
#include<iostream>

using namespace std;

// define a class Temperature

class Temperature
{
	private:
	float fahren, celsius;
	public:
	float conversion(float f)
	{
		fahren=f;
		celsius=(fahren-32)* 5.0/9.0;
		return celsius;
	}
	
};
int main()
{
	// define an object of Temperature class
	Temperature t;
	float f;
	cout<<"Enter Temperature in Fahrenheit=";
	cin>>f;
	// call conversion function with object t
	cout<<"Temperature in Celsius="<<t.conversion(f);

return 0;
}
Source by easycodebook.com #
 
PREVIOUS NEXT
Tagged: #program #Celsius #Fahrenheit #Fahrenheit #Celsius #conversion #class
ADD COMMENT
Topic
Name
3+2 =