www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

#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)
                       {
                       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....."endlendl;
                       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)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)


Views: 2295

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:

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service

.