//j_3_p_4
//comparision of two string
#include <iostream.h>
#include <conio.h>
#include <string.h>
class string
{
char str[20];
public:
void get()
{
cout << "Enter string: " ;
cin.getline(str, 20);
}
int operator > (string);
int operator < (string);
friend operator == (string, string)
};
int string :: operator > (string ob2)
{
if(strcmp(str, ob2.str) > 0)
{
return 1;
}
else
{
return 0;
}
}
int string :: operator < (string ob2)
{
if(strcmp(str, ob2.str) < 0)
{
return 1;
}
else
{
return 0;
}
}
int operator == (string ob1, string ob2)
{
if(strcmp(ob1.str, ob2.str) == 0)
{
return 1;
}
else
{
return 0;
}
}
void main()
{
clrscr();
string obj1, obj2, obj3;
obj1.get();
obj2.get();
if(obj1 > obj2)
{
cout << " First string is greater than second string" << endl;
}
if(obj1 < obj2)
{
cout << " First string is less than second string" << endl;
}
if(obj1 == obj2)
{
cout << " both string is equal" << endl;
}
getch();
}
Comments
Post a Comment