Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program to illusrate data conversion b/w built-in data types and user defined data types (int & float)

Posted By: Easy Tutor     Category: C++ Programming     Views: 2924

A C++ Program to illusrate data conversion b/w built-in data types and user defined data types (int & float).

Code for Program to illusrate data conversion b/w built-in data types and user defined data types (int & float) in C++ Programming

 #include<iostream.h>
 #include<conio.h>


 /*************************************************************************///-----------------------------  distance  ------------------------------///*************************************************************************/class distance
    {
       private:
        int feet;
        float inches;

       public:
        distance()
           {
              feet=0;
              inches=0;
           }

        distance(float meter)
           {
              float f=3*meter;
              feet=f;
              inches=12*(f-feet);
           }

        distance(int f,float i)
           {
              feet=f;
              inches=i;
           }

        void show_distance()
           {
              cout<<"\t Value of feet = "<<feet<<endl;
              cout<<"\t Value of inches = "<<inches<<endl;
           }

        operatorfloat()
           {
              float m=inches/12;
              m+=(feet/3);
              return m;
           }
    };

 /*************************************************************************//*************************************************************************///-----------------------------  Main( )  -------------------------------///*************************************************************************//*************************************************************************/

 main()
    {
       clrscr();

       distance d_1(2.35);
       distance d_2;

       cout<<"\n ***** Basic to User ***** \n"<<endl;

       cout<<" Value of distance d_1 is : "<<endl;
       d_1.show_distance();

       d_2=1.00;

       cout<<"\n Value of distance d_2 is : "<<endl;
       d_2.show_distance();


       distance d_3(5,10.25);

       float m=float(d_3);

       cout<<"\n ***** User to Basic ***** \n"<<endl;

       cout<<" Value of distance d_3 is : "<<m<<endl;

       m=d_2;

       cout<<"\n Value of distance d_2 is : "<<m<<endl;

       getch();
       return 0;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to illusrate data conversion b/w built-in data types and user defined data types (int & float) is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 

Other Interesting Articles in C++ Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!