Programming

Conversion Routine to Convert the Objects of Both Types

Create a class meter_centimeter and another class fit_inches. Write a conversion routine to convert the objects of both types. Conversion from feet inches to meter centimeter.

Source Code

#include<conio.h>
#include<iostream.h>
class FeetInches
{
       private: int ft,in;  float ftin;
       public : FeetInches()
                {ft=0;        in=0;        ftin=0.0;}
                void ftin_conv()
                {
                       ftin=(float)(ft+(in/12));
                }
                float get_ftin()
                {
                       return ftin;
                }
                void input()
                {
                cout<<"Enter distance:"<<endl<<"Feet=";                cin>>ft;
                cout<<"Inches=";        cin>>in;
                }            
};
class MeterCentimeter
{
       private: int m, cm;  float mcm;
       public : MeterCentimeter()
                {m=0;        cm=0;        mcm=0.0;}
                MeterCentimeter(FeetInches feet)
                {        float temp;
                       temp=feet.get_ftin();
                       mcm=temp/3.28;
                }
                void mcm_conv()
                {
                       float temp;
                       m=(int)mcm;
                       temp=mcm-m;
                       cm=temp*100;
                }             
                void display()
                {
                cout<<endl<<endl<<"The distance is "<<m<<" meter and "<<cm<<" centimeters.";
                }
};
void main()
{
       FeetInches feet;
       MeterCentimeter meter;
       clrscr();
       feet.input();
       feet.ftin_conv();
       meter=feet;
       meter.mcm_conv();
       meter.display();
       getch();
}

Tuts

About Author

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