Logo 
Search:

C++ Programming Articles

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

PROGRAM OF OVERLOADING ARITHMETIC OPERATORS ON OBJECTS OF CLASS FLOAT HAVING AN DATA MEMBERS OF TYPE FLOAT

Posted By: Erin Brown     Category: C++ Programming     Views: 30500

WRITE A PROGRAM OF OVERLOADING 4 ARITHMETIC OPERATORS ON OBJECTS OF CLASS FLOAT HAVING AN DATA MEMBERS OF TYPE FLOAT.

Code for PROGRAM OF OVERLOADING ARITHMETIC OPERATORS ON OBJECTS OF CLASS FLOAT HAVING AN DATA MEMBERS OF TYPE FLOAT in C++ Programming

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

class FLOAT
{
    float no;
    public:
    FLOAT(){}
    void getdata()
    {
        cout<<"\n ENTER AN FLOATING NUMBER :";
        cin>>no;
     }
     void putdata()
     {
        cout<<"\n\nANSWER IS                   :"<<no;
     }
     FLOAT operator+(FLOAT);
     FLOAT operator*(FLOAT);
     FLOAT operator-(FLOAT);
     FLOAT operator/(FLOAT);
};
FLOAT FLOAT::operator+(FLOAT a)
{
    FLOAT temp;
    temp.no=no+a.no;
    return temp;
}
FLOAT FLOAT::operator*(FLOAT b)
{
    FLOAT temp;
    temp.no=no*b.no;
    return temp;
}
FLOAT FLOAT::operator-(FLOAT b)
{
    FLOAT temp;
    temp.no=no-b.no;
    return temp;
}
FLOAT FLOAT::operator/(FLOAT b)
{
    FLOAT temp;
    temp.no=no/b.no;
    return temp;
}


main()
{
  clrscr();
  FLOAT a,b,c;
  a.getdata();
  b.getdata();

  c=a+b;
  cout<<"\n\nAFTER ADDITION OF TWO OBJECTS";
  c.putdata();
  cout<<"\n\nAFTER MULTIPLICATION OF TWO OBJECTS";
  c=a*b;
  c.putdata();
  cout<<"\n\nAFTER SUBSTRACTION OF TWO OBJECTS";
  c=a-b;
  c.putdata();
  cout<<"\n\nAFTER DIVISION OF TWO OBJECTS";
  c=a/b;
  c.putdata();
  getch();
}
  
Share: 



Erin Brown
Erin Brown author of PROGRAM OF OVERLOADING ARITHMETIC OPERATORS ON OBJECTS OF CLASS FLOAT HAVING AN DATA MEMBERS OF TYPE FLOAT is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
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!