Write a C++ Program for String concatenation using + operator and String Comparision using <= operator
//String concatenation using + operator
//String Comparision using <= operator #include
#include
#include
class string
{
char *p;
int len;
public:
string()
{}
string(char *a)
{
len=strlen(a);
p=new char[len+1];
strcpy(p,a);
}
string operator + (string o2)
{
string temp;
temp.len=len+o2.len;
temp.p = new char[temp.len + 1];
strcpy(temp.p,p);
strcat(temp.p,o2.p);
return temp;
}
int operator <= (string o2)
{
if(len <= o2.len)
return(1);
else
return(0);
}
void display(void)
{
cout<
}
};
void main()
{
clrscr();
string o1("Vivek"),o2("Patel"),o3;
o1.display();
cout<
o2.display();
cout<
o3=o1+o2;
cout<<"After String Concatenation : ";
o3.display();
cout<
string s1("New Delhi"),s2("New York");
if(s1<=s2)
{
s1.display();
cout<<" is smaller than ";
s2.display();
}
else
{
s2.display();
cout<<" is smaller than ";
s1.display();
}
getch();
}