#include <iostream>
#include <string>
using namespace std;
class student
{
private:
char *str;
int len;
public:
student(){}//无参构造函数
~student(){}//析构函数
student(char *p)//有参构造函数
{
len=my_size(p);
str=new char[len];
for(int i=0;i<len;i++)
{
str[i]=*(p+i);
}
}
student(student& s)//拷贝构造函数
{
this->len=s.len;
str=new char[len];
for(int i=0;i<len;i++)
{
str[i]=s.str[i];
}
}
student& operator=(student &R)
{
this->len=R.len;
this->str=new char[len];
for(int i=0;i<len;i++)
{
str[i]=R.str[i];
}
return *this;
}
const student operator+(const student& R)const//+
{
student tem;
R.len=my_size(R.str);
tem.len=this->len+R.len;
tmp.str=new char[temp.len];
for(int i=0;i<tmp.len;i++)
{
if(i<this->len)
{
tmp.str[i]=R.str[i-(this->len)];
}
}
return tmp;
}
bool operator ==(student&S)//==
{
for(int i=0;i<len;i++)
{
if(str[i]!=S.str[i])
{
break;
}
}
if((this->len==S.len)&&(i==this->len))
{
return 1;
}
else
{
return 0;
}
bool operator >(student&S)//>
{
for(i=0;i<len;i++)
{
if(str[i]!=S.str[i])
{
break;
}
}
if((this->len==S.len)&&(i==this->len))
{
return 1;
}
else
{
return 0;
}
bool operator <(student&S)//<
{
for(i=0;i<len;i++)
{
if(str[i]!=S.str[i])
{
break;
}
}
if((this->len==S.len)&&(i==this->len))
{
return 1;
}
else
{
return 0;
}
bool operator >=(student&S)//>=
{
for(i=0;i<len;i++)
{
if(str[i]!=S.str[i])
{
break;
}
}
if((this->len==S.len)&&(i==this->len))
{
return 1;
}
else
{
return 0;
}
bool operator <=(student&S)//<=
{
for(i=0;i<len;i++)
{
if(str[i]!=S.str[i])
{
break;
}
}
if((this->len==S.len)&&(i==this->len))
{
return 1;
}
else
{
return 0;
}
bool operator !=(student&S)//!=
{
for(i=0;i<len;i++)
{
if(str[i]!=S.str[i])
{
break;
}
}
if((this->len==S.len)&&(i==this->len))
{
return 1;
}
else
{
return 0;
}
void show()
{
cout<<"str="<<this->str<<endl;
}
int my_size(char *s)//长度
{
int len=0;
while(*s!='\0')
{
len++;
s++;
}
return len+1;
}
bool my_empty() //判空
{
return len==0?true:false;
}
};
int main()
{
student s1("hello");
s1.show();
student s2(s1);
s2.show();
student s3;
s3=s2;
s3.show();
if(s1.my_empty()==true)
{
cout<<"null"<<endl;
}
else
{
cout<<"full"<<endl;
}
student s4("hello");
cout<<(s1==s4?"yes":"no")<<endl;
cout<<(s1>s4?"yes":"no")<<endl;
cout<<(s1<s4?"yes":"no")<<endl;
cout<<(s1>=s4?"yes":"no")<<endl;
cout<<(s1<=s4?"yes":"no")<<endl;
cout<<(s1!=s4?"yes":"no")<<endl;
student s5;
s5=s1+s4;
s5.show();
return 0;
}