Create two classes Celsius and Fahrenheit to store temperature in terms of Celsius and Fahrenheit respectively.Include necessary functions to read and display the values.Define conversion mechanism to convert Celsius object to Fahrenheit object and vice versa. Show both types of conversions in main function.
CODING:
#include<iostream.h>
#include<conio.h>
class celsius;
class fehrenheit
{
int f;
public:
fehrenheit(){}
void set(){cout<<"ENTER THE FEHRENHEIT :";cin>>f;}
void disp(){cout<<"CONVERT TO FEHRENHEIT:"<<f;}
int get_f(){return f;}
fehrenheit(celsius c1);
};
class celsius:public fehrenheit
{
int c;
public:
celsius(){}
celsius(fehrenheit f1)
{
c=(f1.get_f()-32)/1.8;
}
void set(){cout<<"\nENTER THE CELSIUS:";cin>>c;}
void disp(){cout<<"CONVERT TO CELSIUS:"<<c;}
int get_c(){return c;}
};
fehrenheit::fehrenheit(celsius c1)
{
f=(c1.get_c()*1.8)+32;
}
void main()
{
fehrenheit f1;
celsius c1;
clrscr();
f1.set();
c1=f1;
c1.disp();
c1.set();
f1=c1;
f1.disp();
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class celsius;
class fehrenheit
{
int f;
public:
fehrenheit(){}
void set(){cout<<"ENTER THE FEHRENHEIT :";cin>>f;}
void disp(){cout<<"CONVERT TO FEHRENHEIT:"<<f;}
int get_f(){return f;}
fehrenheit(celsius c1);
};
class celsius:public fehrenheit
{
int c;
public:
celsius(){}
celsius(fehrenheit f1)
{
c=(f1.get_f()-32)/1.8;
}
void set(){cout<<"\nENTER THE CELSIUS:";cin>>c;}
void disp(){cout<<"CONVERT TO CELSIUS:"<<c;}
int get_c(){return c;}
};
fehrenheit::fehrenheit(celsius c1)
{
f=(c1.get_c()*1.8)+32;
}
void main()
{
fehrenheit f1;
celsius c1;
clrscr();
f1.set();
c1=f1;
c1.disp();
c1.set();
f1=c1;
f1.disp();
getch();
}
Comments
Post a Comment