C++ Programming Blog

 
 
 

Image

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



 //----------------------------  distance  -------------------------------//


 class distance
    {
       private:
        int feet;
        float inches;

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

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

        distance operator -(distance);

        void get_distance()
           {
              cout<<\"\\t Enter the feet = \";
              cin>>feet;

              cout<<\"\\t Enter the inches = \";
              cin>>inches;
           }

        void show_distance()
           {
             cout<<feet<<\" f - \"<<inches<<\"\'\"<<endl;
           }
     };



 //------------------------  Function Definitions  -----------------------//




 //---------------------------  operator-(distance)  ---------------------//


 distance distance::operator-(distance d_1)
    {
       int f=feet-d_1.feet;
       float i=inches-d_1.inches;

       if(i<=0)
      {
         i+=12.0;
         f--;
      }

       return distance(f,i);
    }


 main( )
    {
       clrscr();

       distance d_1;
       distance d_2(11, 6.25);
       distance d_3;
       distance d_4;

       cout<<\"\\n Value of d_1 : \"<<endl;
       d_1.get_distance();

       d_3=d_1-d_2;

       d_4=d_1-d_2-d_3;

       cout<<\"\\n Value of d_1 = \";
       d_1.show_distance();

       cout<<\"\\n Value of d_2 = \";
       d_2.show_distance();

       cout<<\"\\n Value of d_3 = \";
       d_3.show_distance();

       cout<<\"\\n Value of d_4 = \";
       d_4.show_distance();

       getch();
       return 0;
    }

    Related Post:
  1. Program that takes input of vector elements and performs multiplication operation, and input/output (&gt;&gt;, &lt;&lt;) using operator overloading

  2. Program to show the projection of 3D objects using Orthographics Projection Parallel onto xy-plane

  3. Program to draw a Cubic Bezier Curve

  4. Program to read a Non-Linear equation in one variable, then evaluate it using Bisection Method and display its kD accurate root

  5. Program to draw an Elliptical Arc using Trigonometric Method

  6. Program that displays result of students by compact if-else notation

  7. Program to illustrate the implementation of linked list as a Queue

  8. Program to illustrate the Insertion Sort

  9. Program that provides an example of dynamic memory allocation

  10. Program that performs addition of 2 matrix using friend function

  11. Program that prints first 20 integers in reverse order (using while loop )

  12. Program to display DFA

  13. Program illustrating operator overloading

  14. Program to implement the Kurskals Algorithm to solve Minimum Cost Spanning Tree Problem (MST) using Graphics

  15. Program to estimate the Differential value of a given function using Trapezoidal Rule [Predictor-Corrector Scheme (PC2)]

  16. Program to illustrate the implementation of Rotation Transformation along a Pivot Point

  17. Program to illustrate supplying of values to pointer variables

  18. Program to read a Linear System of Equations,then evaluate it by using Jacobis Itrative Method and show the result

  19. Program to illustrate unary operator(decrement operator) overloading with return type

  20. Program that takes 10 integer from a user and perform addition using class