Paste this code in C++
#include <iostream>
using namespace std;
class Location
{
int l1;
int l2;
public:
Location();
Location(int lon,int lat);
void view();
Location operator ++();
Location operator --();
void* operator new (size_t size);
void operator delete( void * ptr );
};
Location::Location()
{
l1=0;
l2=0;
}
Location::Location(int lon,int lat)
{
l1=lon;
l2=lat;
}
void Location::view()
{
cout<<endl<<"Longitude : "<<l1<<endl;
cout<<"Latitude : "<<l2<<endl<<endl;
}
void* Location::operator new(size_t size)
{
cout<<"Overloaded new operator called....." <<endl;
void * rtn = malloc (size ) ;
return rtn;
}
Location Location::operator ++()
{
++l1;
++l2;
}
Location Location::operator --()
{
--l1;
--l2;
}
void Location :: operator delete( void *memory )
{
cout<<"Overload delete operator called....."<<endl<<endl;
free( memory );
}
main()
{
system("cls");
Location l1(10,20), *l2= new Location(30,40);
cout<<endl<<"Coordinates for Location 1:";
l1.view();
++l1;
cout<<"After applying overloaded ++ operator on Location 1 : ";
l1.view();
cout<<"Coordinates for Location 2:";
l2[0].view();
--(*l2);
cout<<"After applying overloaded -- operator on Location 2 : ";
l2[0].view();
delete l2;
system("pause");
}
0 comments:
Post a Comment