/*
write a c++ program to consider the following class mystring
class mystring
{
char str[100];
public:\\method
};
overload operator == to compare two string
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
int i=0,x;
class mystring
{
char str[20];
public:void accept()
{
i=i+1;
cout<<"\nenter string "<<i<<":-";
cin>>str;
}
int operator ==(mystring &m2);
};
int mystring::operator ==(mystring &m2)
{
x=strcmp(str,m2.str);
return x;
}
int main()
{
mystring m1,m2;
clrscr();
m1.accept();
m2.accept();
m1==m2;
if(x==0)
cout<<"\nboth strings are same";
else
cout<<"\nstring are not same";
getch();
return 0;
}
/*
enter string 1:-peer
enter string 2:-peer
both strings are same
*/
/*
enter string 1:-peer
enter string 2:-saab
string are not same
*/
write a c++ program to consider the following class mystring
class mystring
{
char str[100];
public:\\method
};
overload operator == to compare two string
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
int i=0,x;
class mystring
{
char str[20];
public:void accept()
{
i=i+1;
cout<<"\nenter string "<<i<<":-";
cin>>str;
}
int operator ==(mystring &m2);
};
int mystring::operator ==(mystring &m2)
{
x=strcmp(str,m2.str);
return x;
}
int main()
{
mystring m1,m2;
clrscr();
m1.accept();
m2.accept();
m1==m2;
if(x==0)
cout<<"\nboth strings are same";
else
cout<<"\nstring are not same";
getch();
return 0;
}
/*
enter string 1:-peer
enter string 2:-peer
both strings are same
*/
/*
enter string 1:-peer
enter string 2:-saab
string are not same
*/
No comments:
Post a Comment