PROGRAM FOR COMPARISION OF STRING USING OPERATOR OVERLOADING
//comparision of string #include #include const int SIZE=50; enum boolean{FALSE,TRUE}; class string { public: char str[SIZE];
string() { strcpy(str,””); } void read() { cin>>str; } void echo() { cout< } boolean operator <(string s) { if (strcmp(str,s.str)<0) return TRUE; else return FALSE; } boolean operator >(string s) { if (strcmp(str,s.str)>0) return TRUE; else return FALSE; } boolean operator <(char *mystr) { if (strcmp(str,mystr)==0) return TRUE; else return FALSE; } };
void main() { string str1,str2;
{
cout<<”enter string1:”; str1.read(); cout<<”enter string2:”; str2.read(); cout<<”comparison status:”; str1.echo(); if(str1 cout<<”<”; else if(str1>str2) cout<<”>”; else cout<<”=”; str2.echo(); cout< } }
Output: enter string1:ashish enter string2:ashish++ comparision status:ashishPress any key to continue
|
No responses found. Be the first to respond and make money from revenue sharing program.
|