silver boy
Registered User
- تاریخ عضویت
- 7 می 2011
- نوشتهها
- 56
- لایکها
- 0
سلام این سورس کد مربوط به سربار گذاری عملگر هاست دو تا ازش نوشتم ولی اور هاش باهم فرق می کنه لطفا کمک کنید
اینم دومی ش
این دومی 2 تا اور میده:wacko:
کد:
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
class string{
friend ostream & operator<<(ostream & , const string &);
friend istream & operator>>(istream & , string &);
public:
string();
void getstring();
string& operator = (cost string &);
string & operator +=(const string &);
bool operator ! () const;
bool operator == (const string &) const ;
bool operator < (const string &) const ;
bool operator = (const string &) const ;
bool operator > (const string &) const ;
bool operator <= (const string &) const ;
bool operator >= (const string &) const ;
bool getlength() const ;
private:
int length;
char st[80];
void setstring (char *);};
string::string (){
st[0]='\0';}
void string ::getstring (){
cout << "pleease enter string :"<<endl;
gets(st);
this-> getlength();}
string& string::operator=(const string & right){
setstring(rigth.st);
return *this;}
string & string::operator += (const string & right){
strcat (this ->st , right.st);
return *this ;}
bool string:: operator !() const{
return (length==0);}
bool string ::operator ==(const string & right) const{
return(strcmp (st , right.st));}
bool string ::operator !=(const string & right) const{
return!(strcmp(st,right.st))==0);}
bool string ::operator <=(const string & right) const{
return(strcmp(st,right.st)<=0);}
bool string ::operator >(const string & right) const{
return (strcmp(st, right.st)>0);}
bool string ::operator >=(const string & right) const{
return (strcmp(st, right.st)>=0);}
void string ::setstring (const char *st2){
strcpy(st, st2);}
void string::getlength() const{
length= strlen(st);}
ostream & operator << (ostream & output , const string & s){
output<<s.st;
return output;}
istream&operator>>(istream & input , string &s){
input>>s.st;
s.getlength();
return input;}
void main(){
string s1, s2, s3, s4;
cout<<"please enter a string :"<<endl;
cin>>s1;
cout<<"please enter a string :"<<endl;
s2.getstring();
s3=s1; s4=s3; s4=s2;
cout<<"s1==s2?";
cout<<((s1==s2)?"true" : "false")<<endl;
cout<<"(s1>s2)?";
cout<<((s1>s2)?"true" : "false")<<endl;
//else
cout<<"s4 is nul? ";
cout<<((s4!)?"true" : "false")<<endl;
cout<<s1<<endl;
cout<<s2<<endl;
cout<<s3<<endl;
cout<<s4<<endl;}
اینم دومی ش
کد:
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>
class string{
friend ostream& operator<<(ostream&,const string &);
friend istream& operator>>(istream&, string &);
public:
string();
void getstring();
string& operator=(const string &);
string& operator+=(const string &);
bool operator!()const;
bool operator==(const string &)const;
bool operator<(const string &)const;
bool operator!=(const string &)const;
bool operator>(const string &)const;
bool operator<=(const string &)const;
bool operator>=(const string &)const;
void getlenght()const;
private:
int lenght;
char st[80];
void setstring(char *);};
string::string()
{
st[0]='\0';}
void string::getstring()
{
cout<<"please enter string:";
gets(st);
this->getlenght();
}
string& string::operator=(const string & right);
{setstring(right.st);
return *this;}
string& string::operator+=(const string & right)
{strcat(this->st,right.st);
return *this;}
bool string::operator!()const
{return(lenght==0);}
bool string::operator ==(const string & right)const
{return(strcmp(st,right.st)==0);}
bool string::operator <(const string & right)const
{return (strcmp(st,right.st)<0);}
bool string::operator !=(const string & right)const
{return !(strcmp(st,right.st)==0);}
bool string::operator <=(const string & right)const
{return (strcmp(st,right.st)<=0);}
bool string::operator >(const string & right)const
{return(strcmp(st,right.st)>0);}
bool string::operator >=(const string & right)const
{return(strcmp(st,right.st)<=0);}
void string::setstring(const char *st2)
{strcpy(st,st2);}
void string::getlenght() const
{lenght=strlen(st);}
ostream& operator<<(ostream&output,const string & s)
{output<<s.st;
return output;}
istream& operator>>(istream&input,string& s)
{input>>s.st;
s.getlenght();
return input;}
void main(){
string s1,s2,s3,s4;
cout<<"please enter a string:"<<endl;
cin>>s1;
cout<<"please enter a string:"<<endl;
s2.getstring();
s3=s1;
s4=s3;
s4+=s2;
cout<<"s1==s2?";
cout<<((s1==s2)?"true":"false")<<endl;
cout<<"(s1>s2)?";
cout<<((s4>s2)?"true":"false")<<endl;
cout<<"s4 is NULL?";
cout<<((s4)!:?"true":"false")<<endl;
cout<<s1<<endl;
cout<<s2<<endl;
cout<<s3<<endl;
cout<<s4<<endl;}