C++ Programming

Program that Can Convert Distance (Meter, Centimeter)

Write a program that can convert distance (meter, centimeter) to meter’s measurement in float and vice versa. Make a class distance with two data members meter and centimeter. You can add function as per your requirement.

Source Code

#include<iostream.h>
#include<conio.h>
#include<math.h>
class distance
{
private:
float meter;
float centimeter;
public:
distance()
{
meter=0;
centimeter=0;
}
operator float()
{
float m;
m=(meter+(centimeter/100));
return m;
}
void getdistance()
{
cout<<"Enter length in meter and centimeter ";
cin>>meter>>centimeter;
}
};
void main()
{
distance d1;
float m1;
d1.getdistance();
m1=d1;
cout<<"Length in meters is: "<<m1;
getch();
}
Back to top button