#include <iostream.h>
#include <string.h>
#include <conio.h>
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<<p;
}
};
void main()
{
clrscr();
string o1("Vivek"),o2("Patel"),o3;
o1.display();
cout<<endl;
o2.display();
cout<<endl<<endl;
o3=o1+o2;
cout<<"After String Concatenation : ";
o3.display();
cout<<endl<<endl<<endl;
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();
}
#include <string.h>
#include <conio.h>
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<<p;
}
};
void main()
{
clrscr();
string o1("Vivek"),o2("Patel"),o3;
o1.display();
cout<<endl;
o2.display();
cout<<endl<<endl;
o3=o1+o2;
cout<<"After String Concatenation : ";
o3.display();
cout<<endl<<endl<<endl;
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();
}
0 comments:
Post a Comment