We have been working very hard since 2009 to facilitate in learning Read More. We can't keep up without your support. Donate.

www.vustudents.ning.com

 www.bit.ly/vucodes + Link For Assignments, GDBs & Online Quizzes Solution www.bit.ly/papersvu + Link For Past Papers, Solved MCQs, Short Notes & More

# CS201 Assignment 4 solution laste date 26 june 2012 (Created By tahir)

#include <iostream.h>

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()
{
coutendl"Longitude : "l1endl;
cout"Latitude : "l2endlendl;
}

void* Location::operator new(size_t size)
{
void *   rtn   = malloc (size ) ;
return   rtn;
}

Location Location::operator ++()
{
++l1;
++l2;
}

Location Location::operator --()
{
--l1;
--l2;
}

void   Location :: operator   delete( void *memory )
{
free( memory );
}

main()
{

system("cls");

Location l1(10,20), *l2= new Location(30,40);

coutendl"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[0];
cout"After applying overloaded -- operator on Location 2 : ";
l2[0].view();
delete l2;
system("pause");

}

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

Views: 2292

Attachments:

### Replies to This Discussion

object k through he hai dear..more clarify me ur point ..

but muzamil yah compail ni ho rhi

there is not wrong with this file ..go to first discussion about this assignment u will get the whole idea..

Brother! what the heck "malloc" is? where you did declare this?

malloc and calloc function for allocating a memory ..in this assignment u havce to overload new operator coz object always can allocate the memory by new operator in dynamically..so u have to defined a malloc or calloc function to allocate memory in the definition of overloading new operator ..okay ?

similarly when we are allocating memory by malloc or calloc functions then its our responsibility to free the memory allocated... so u have to overload delete operator for it..

can u plz tell k press enter to continue likhne k liye kon sa code use hota hai aur kahan pe??

system("PAUSE");

Thanks brther!

thanks a lot

complte and 100% correct

Attachments:

## Latest Activity

11 minutes ago
15 minutes ago
15 minutes ago
+!!!★彡 "Å⫶l̊⫶å⫶n̊⫶ "彡★✓ liked Omar's discussion Thanks giving
16 minutes ago
18 minutes ago
+!!!★彡 "Å⫶l̊⫶å⫶n̊⫶ "彡★✓ liked ★彡[ꜱʜʏɴᴀ]彡★'s discussion Aksar
19 minutes ago
32 minutes ago
36 minutes ago
★彡[ꜱʜʏɴᴀ]彡★ posted discussions
4 hours ago
7 hours ago
+ + + + " Tw!nkle " posted a discussion

8 hours ago
9 hours ago