Example : For Converting Degree to Radian and vice-versa
#include<iostream.h>
class
radian
{
private:
float
r1;
public:
radian()
{
r1=0.0;
}
radian(float r2)
{
r1=r2;
}
float
getrad()
{
return
r1;
}
void
input()
{
cout<<"\n\n\tEnter
Radian : ";
cin>>r1;
}
void disp()
{
cout<<"\n\t
Radian = "<<getrad();
}
};
class degree
{
private:
float
d1;
public:
degree()
{
d1=0.0;
}
degree(radian
r1)
{
d1=(180.0/((22/7.0))*r1.getrad());
}
operator radian()
{
return (radian((d1*22/7.0)/180.0));
}
void input()
{
cout<<"\n\tEnter Degree:";
cin>>d1;
}
void disp()
{
cout<<"\n\tDegree =
"<<d1;
}
};
void
main()
{
clrscr();
degree d1,d2;
radian r1,r2;
d1.input();
r1=d1;
r1.disp();
r2.input();
d2=r2;
d2.disp();
getch();
}
Example : For Converting Rupee to Dollar and vice-versa
#include<iostream.h>
class
rupees
{
private:
float r1;
public:
rupees()
{
r1=0.0;
}
rupees(float
r2)
{
r1=r2;
}
float getrupees()
{
return r1;
}
void input()
{
cout<<"\n\n\tEnter the
Rupees : ";
cin>>r1;
}
void disp()
{
cout<<"\n\tRupees =
"<<getrupees();
}
};
class
dollars
{
private:
float d1;
public:
dollars()
{
d1=0.0;
}
dollars(rupees r1)
{
d1=r1.getrupees()/50;
}
float getdollars()
{
return d1;
}
operator rupees()
{
return (rupees(d1*50));
}
void input()
{
cout<<"\n\tEnter the
Dollar : ";
cin>>d1;
}
void disp()
{
cout<<"\n\tThe Dollar :
"<<d1;
}
};
void
main()
{
clrscr();
dollars
do1,do2;
rupees
ru1,ru2;
do1.input();
ru1=do1;
ru1.disp();
ru2.input();
do2=ru2;
do2.disp();
getch();
}