Wednesday, October 1, 2014

WAP that can convert the Distance (meter, centimeter) to meters measurement in float and vice versa. Make a class distance with two data members meter and centimeter. You can add function members as per your requirements.

Code:
#include
#include
class distance
{
            float meter,centimeter;
            public:
            distance()
            {
                        meter=0;
            }
            distance(float l)
            {
                        meter=0.01*l;
            }
            void show()
            {
                        cout<<"\nLength (in meter):"<
            }
            operator float()
            {
                        float length;
                        length=meter*100.0;
                        return(length);
            }
            void get()
            {
                        cout<<"\n\nEnter the length in meter:";
                        cin>>meter;
            }
};
void main()
{
            clrscr();
            distance d1;
            float len;
            cout<<"\nEnter the length in centimeter:";
            cin>>len;
            d1=len;
            d1.show();
            d1.get();
            len=d1;
            cout<<"\nLength in centimeter:"<
            getch();

}

No comments:

Post a Comment