Problem Statement: Location Calculation
You are required to write a program for calculating location somewhere on the map. There are two parameters (coordinates) used in calculating a location. One is longitude and the other is latitude. You need to overload ++, —, new and delete operators for this.
- You are required to create a class named Location.
- It will have two private data member longitude and latitude.
- These data members will be assigned values through constructor parameters. For example obj1(20,30).
- Overloaded ++ operator will increase the both longitude and latitude values by one, overloaded — will decrease both by one.
- By overloading new operator, you will allocate the memory dynamically for the object of class Location.
- The overloaded delete operator will free (de-allocate) the allocated memory.
- You have to create two objects of class Location. One object will be created through overloaded new operator and other will be created without it.
- A message “Overloaded new operator called”, embedded inside overloading function for new operator, should be displayed when the object is created through new operator.
- Similarly, a message “Overload delete operator called” should be displayed upon calling overloaded function of delete operator.
- Assign the values (10, 20) and (30, 40) for longitude and latitude for object 1 and 2 respectively.
using namespace std
location(int j,int i);
void* operator new (size_t size);
location operator ++();
location operator –();
location::location(int j,int i)
cout” Longitude : ” endl;
cout” Latitude : ” endl;
void* location::operator new(size_t size)
cout” Overloaded New operator Called”endl;
location location::operator ++()
location location::operator –()
cout” After calling Overloaded ++ operator on location 1″endl;
cout”Coordinate for location 2 :”endl;
cout” After calling Overloaded — operator”endl;