#include<iostream.h>
#include<string.h>
#include<conio.h>
class mystring
{
char str[30];
int length;
public:
void accept()
{
cin>>str;
length=strlen(str);
}
int check(char ch);
int check(mystring c2);

};
int mystring::check (char ch)
{
for(int i=0;i<length;i++)
{
if(str[i]==ch)
return i+1;
}
return -1;
}

mystring::check(mystring c2)
{
if(length==c2.length)
return 1;
else
return 0;
}

int main()
{
mystring c1,c2,c3;
clrscr();
cout<<"\nEnter the first string : ";
c1.accept();
cout<<"\nEnter the second string : ";
c2.accept();
int n1,n2;

n1=c1.check(c2);
if(n1==1)
cout<<"\n\nBoth strings are having equal length";
else
cout<<"\n\nBoth strings are not having equal length";

char ch;
cout<<"\n\nEnter a character to check whether it is present in a first string or not : ";
cin>>ch;
n2=c1.check(ch);
if(n2==-1)
cout<<"\n"<<ch<<" is not present in first string";
else
cout<<"\n"<<ch<<" is present in first string at "<<n2<<" position";

getch();
return 0;
}


Post a Comment

Previous Post Next Post