Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!

C++ Programming

Program that Can Convert Distance (Meter, Centimeter)

Convert Distance

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();
}
Avatar

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like

program to find leap year
C++ Programming

C++ Program to Find Leap Year by Using Function

  • March 3, 2016
Write a program to find if the inputted year is a leap year or not by using the concept of