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

#include<iostream>
#include<conio.h>
using namespace std;
class Demo
{
float km;
public:
Demo()
{

}
Demo(float m)
{
km=m/1000;
}
void display()
{
cout<<“Length in kilometer:”<<km;
}
};
main()
{
Demo d;
float m;
cout<<“enter length in meter:”;
cin>>m;
d=m;
d.display();
getch();
}

Output:

Leave a Reply

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