0
/* Reena Rankawat
   Q89.Write a program to illustrate overloading of comma operator(,).  */

#include<iostream.h>
#include<conio.h>
//using namespace std;
class loc
{
    private:
        int longitude,latitude;
    public:
        loc(void)
        {
        }
        loc(int lg,int lat)
        {
            longitude=lg;
            latitude=lat;
        }
        void show(void)
        {
            cout<<"\n Latitude: "<<latitude;
            cout<<"\n Longitude: "<<longitude;
        }
        loc operator +(loc obj2);
        loc operator ,(loc obj2);
};
//overloading , operator
loc loc::operator ,(loc obj2)
{
    loc temp;
    temp.longitude=obj2.longitude;
    temp.latitude=obj2.latitude;
    cout<<"\n Latitude: "<<obj2.latitude;
    cout<<"\n Longitude: "<<obj2.longitude;
    return temp;
}
loc loc::operator +(loc obj2)
{
    loc temp;
    temp.longitude=longitude+obj2.longitude;
    temp.latitude=latitude+obj2.latitude;
    return temp;
}
int main(void)
{
    loc obj1(30,40),obj2(50,60),obj3(0,0);
    clrscr();
    cout<<"\n\n\n";
    obj1.show();
    obj2.show();
    obj3.show();
    obj1=(obj1,obj2+obj1,obj3);
    obj1.show();
    getch();
    return 0;
}
2
Contributors
1
Reply
6
Views
4 Years
Discussion Span
Last Post by Rashakil Fol
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.