A program to convert distance in meter to kilometer using user defined type to basic conversion in C++

#include<iostream>
#include<conio.h>
using namespace std;
class Demo
{
float m;
public:
void setdata()
{
cout<<“enter length in meter:”;
cin>>m;
}
operator float()
{
float km;
km=m/1000;
return km;
}
};
main()
{
Demo d;
float km;
d.setdata();
km=d;
cout<<“Length in kilometer:”<<km;
getch();
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *