Create a class FLOAT that contains one float data member. Overload all the four arithmetic operators so that they operate on the objects of FLOAT.

/*
    Create a class FLOAT that contains one float data member.
    Overload all the four arithmetic operators so that they operate on the objects of FLOAT.
*/
#include<iostream>
using namespace std;
class FLOAT
{
    float a;

    public:
            FLOAT(float a)
            {
                this->a=a;
            }

            float operator+(FLOAT F)
            {
                return(a+F.a);
            }

            float operator-(FLOAT F)
            {
                return(a-F.a);
            }

            float operator*(FLOAT F)
            {
                return(a*F.a);
            }

            float operator/(FLOAT F)
            {
                return(a/F.a);
            }

};


int main()
{
    FLOAT f1(10.10),f2(20.20);

    cout<<"\n\n Operator + : "<<f1+f2;
    cout<<"\n\n Operator - : "<<f1-f2;
    cout<<"\n\n Operator * : "<<f1*f2;
    cout<<"\n\n Operator / : "<<f1/f2;

    return 0;
}




Previous
Next Post »