#Include #Include Using Namespace Class Public Char
#Include #Include Using Namespace Class Public Char
#include<string.h>
using namespace std;
class mystring
{
public :
char *arr;
mystring()
{
arr=NULL;
cout<<"I am Constructor"<<endl;
}
void operator=(char ch)
{
if(arr!=NULL)
{
free(arr);
}
arr=(char*)malloc(2);
arr[0]=ch;
arr[1]='\0';
}
void operator=(char *t)
{
if(arr!=NULL)
{
free(arr);
}
int l1=strlen(t);
arr=(char*)malloc(l1+1);
strcpy(arr,t);
}
void operator=(mystring scopy)
{
if(arr!=NULL)
{
free(arr);
}
int l1=strlen(scopy.arr);
arr=(char*)malloc(l1+1);
strcpy(arr,scopy.arr);
}
int operator>(mystring s)
{
int d;
d=strcmp(arr,s.arr);
if(d>0)
{
return 1;
}
else
{
return 0;
}
}
int operator<(mystring s)
{
int d;
d=strcmp(arr,s.arr);
if(d<0)
{
return 1;
}
else
{
return 0;
}
}
void display()
{
puts(arr);
}
};
void main()
{
mystring s1,s2;
s1="Sahibzada Muhammad Shahid Khan Afridi "; //char *t
s1.display();
s1='a'; //char ch
s1.display();
s2="Ali"; //mystring temp
s2.display();
if(s1>s2)
{
s1="If Condition";
}
else
{
s1="else Condition";
}
s1.display();