Operator Overloading with Pointers


This program is for Operator Overloading in C++ . This is a part of Mumbai University MCA Colleges C++ Programs MCA. It performs the overloading of  '+' and '*' operators. 


C++ or CPP provides us to over load the different operators but the basic working of operators remains the same. Here we have overloaded the operators in a different way by using the local variables and used pointers as reference.



#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

class OverLoad
{
char *s1,*s2;
public:
void get(char &a,char &b);
void put();
char* operator +();
char* operator *();
};
void OverLoad :: get(char &a,char &b)
{
s1=&a;
s2=&b;

}

void OverLoad :: put()
{
cout<<"String 1 : "<<s1;
cout<<"\nString 2 : "<<s2;

}

char* OverLoad :: operator +()
{
strcat(s1,s2);
return s1;
}

char* OverLoad :: operator *()
{
strrev(s1);
return s1;
}

void main()
{
char *a,*b,*c,*d;
OverLoad obj;
clrscr();
cout<<"Enter First String :";
gets(a);
cout<<"\nEnter Second String : ";
gets(b);
obj.get(*a,*b);
obj.put();
c=+obj;
cout<<"\n\nConcatinated String : "<<c;
d=*obj;
cout<<"\n\nReversed String : "<<d;
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment