www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

# CS201 Assignment No 04 Solution & Discussion Due Date:26-06-2012

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.

Detailed Description:

• 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.

Views: 5598

Attachments:

### Replies to This Discussion

man ..

/* Assignment 04*/
using namespace std;
#include
class location
{
int longitude;
int latitude;
public:
location();
location(int j,int i);
void display();
void* operator new (size_t size);
location operator ++();
location operator --();

};
location::location()
{
longitude=0;
latitude=0;
}
location::location(int j,int i)
{
longitude=j;
latitude=i;
}

void location::display()
{
cout"\n Longitude : "longitude;
cout"\n Latitude : "latitude;
}

void* location::operator new(size_t size)
{
void *pointer=malloc(size);
return pointer;
}

location location::operator ++()
{
longitude+=1;
latitude+=1;
}

location location::operator --()
{
--longitude;
--latitude;
}

main()
{
location *loc,l2;
loc=new location(10,20);
loc[0].display();
++loc;
loc[0].display();
cout"\n";
l2=location(30,40);
l2.display();
--l2;
l2.display();
system ("pause");
delete loc,l2;
}

Mujhe afsoos se kehna Parta hai ke loog yahan se code copy kar ke doosri site par le jate hain or waqas jese loog hum par ilzam lagteen hain

Is lia main ne Eik Chota sa error chora hai wo app khud thek kar lena

yasir bhai jo kuch nahi ker sakte wo sirf ilzam he laga sakte hen, ignore it

yes, i agree

aap kar sakty ho tu error bata do na  kyo yasir ke autaha rahi ho

some one of cs 201 plz i need a help add me on.....

#include <iostream.h>
using namespace std;

class location
{
int longitude;
int latitude;
public:
location();
location(int j,int i);
void display();
void* operator new (size_t size);
location operator ++();
location operator --();

};
location::location()
{
longitude=0;
latitude=0;
}
location::location(int j,int i)
{
longitude=j;
latitude=i;
}

void location::display()
{
cout" Longitude : " endl;
cout" Latitude : " endl;
}

void* location::operator new(size_t size)
{
cout" Overloaded New operator Called" endl;
void *pointer=malloc(size);
return pointer;
}

location location::operator ++()
{
longitude+=1;
latitude+=1;
}

location location::operator --()
{
--longitude;
--latitude;
}

main()
{
location *loc,l2;
loc=new location(10,20);
loc[0].display();
cout" After calling Overloaded ++ operator on location 1" endl;
++loc;
loc[0].display();
cout"Coordinate for location 2 :"endl;
l2=location(30,40);
l2.display();
--l2;
cout" After calling Overloaded -- operator" endl;
l2.display();
system ("pause");
delete loc,l2;
}
yah lo sir jee its  complied  and run still your solution is not correct :P

solution .. by yasir saleem  is yet not correct .. ++ and --  can not  work  in  codeings ..

Attachments:

nhi ho rha tu dear thora sa mind lagao ..bs ..

Dear all,

Main ne pahle hi keh dia aik chora sa error jan boojh kar chora hai. Ye run bhi hoga or compile bhi sirf app logo ko aik word add karna hai. Wo bhi main be waqas ke comment ki waja se. Although you have to add only "one" character and it will work fine

wo ak  word #include <cmath> kay  elava aur kayai hy ..

Sadia sis ap ke prog main values to pass he nai huin. Plz correct it

1

2

3

4

5

## Latest Activity

2 hours ago
2 hours ago
2 hours ago

3 hours ago

3 hours ago

3 hours ago

### So Cute(^_^)

3 hours ago
♥ + Kamli + ♥ liked иαвєєℓ αнмє∂'s discussion !!!! Naam Tou Likh Dun !!!!
3 hours ago