MATHMATICAL OPERATIONS ON STRINGS
<string.h>
<iostream>
class String
{
*p;
len;
:
String()
{
len=0;
p=0;
};
String(const char *s);
String(const String & s);
~String()
{
p;
}
String operator+(const String &s,const String &t);
operator<=(const String &s, const String &t);
show(const String s);
};
String :: String(const char *s)
{
p=new char[len+1];
strcpy(p,s);
}
String:: String(const String &s)
{
len=s.len;
p=new char[len+1];
strcpy(p,s.p);
}
String operator +(const String &s, const String &t)
{
String temp;
temp.len=s.len+t.len;
temp.p=new char[temp.len+1];
strcpy(temp.p,s.p);
strcat(temp.p,t.p);
return(temp);
}
operator<=(const String &s, const String &t)
{
m=strlen(s.p);
n=strlen(t.p);
(m<=n)
(1);
(0);
}
show(const String s)
{
std::cout<<s.p;
}
main()
{
String s1="new";
String s2="york";
String s3="delhi";
String t1,t2,t3;
t1=s1;
t2=s2;
t3=s1+s3;
std::cout << "\n t1=";
show(t1);
std::cout << "\n t2=";
show(t2);
std::cout << "\n";
std::cout << "\nt3=";
show(t3);
std::cout << "\n\n";
if (t1<=t3)
{
show(t1);
std::cout << "Smaller than";
show(t2);
std::cout << "\n";
}
{
show(t3);
std::cout << "smaller than ";
show(t1);
std::cout << "\n";
}
0;
} ;
|