#include
#include
class string
{
private :
int len;
char a[80];
public:
void getdata();
void display();
friend string operator+( string s1 , string s2);
friend void copy();
friend void paly();
friend void rever();
};
void string :: getdata()
{
cout << "ENTER THE STRING:";
cin >> a;
int i;
i=0;
while((a[i]!='\0') && (i<80) )
{
i++;
}
len=i;
}
void string :: display()
{
cout << endl << a;
}
string operator+( string s1, string s2)
{
string s;
char str[25],str1[10],str2[10];
char *p,*p1;
int len1,len2;
len1=s1.len;
len2=s2.len;
int i,j;
p=s1.a; p1=s2.a;
for(i=0;i<25;i++)
s.a[i]=0;
cout<<"STRING IS:";
for(i=0;i
for(j=0;j
s.a[i]=*(p1+j);
i++;
}
s.len=len1+len2;
return s;
}
void copy()
{
string s1,s2;
char str1[20],str2[20],*p,*p1;
int i;
cout<<"WELCOME TO COPY THE STRING";
s1.getdata();
p=s1.a;
for(i=0;i<20;i++)
s2.a[i]=0;
cout<<"THE COPIED STRING IS:";
for(i=0;i
cout<
void paly ()
{
string s;
int flag=0,i,len=0;
char str[50],*p;
cout << "WELCOME TO TEST THE PALINDROME PROPERTY" << endl ;
s.getdata();
p=s.a;
for(i=0;i
if(*(p+i)!=*(p+(s.len-i-1)))
flag++;
}
if(flag==0)
cout<<"\nTHE STRING IS PALINDROME.";
else
cout<<"\nTHE STRING IS NOT PALINDROME.";
}
void rever()
{
string s;
char str[10];
char *p,*p1;
int len=0,i;
cout << "WELCOME TO REVERSE THE STRING " << endl ;
s.getdata();
p1=s.a;
cout<<"REVERSED STRING IS:";
for(i=s.len;i>=0;i--)
cout<<*(p1+i);
getch();
}
void main()
{
string p,q,r;
int i,j;
int c;
clrscr();
cout << "WELCOME";
do {
cout << endl << "1.Read & display a string.";
cout << endl << "2.Reverse a string";
cout << endl << "3.Copy the string";
cout << endl << "4.Concatenate the strings";
cout << endl << "5.To test property Palindrome";
cout << endl << "6.Exit";
cout << endl << "Enter ur choice:";
cin >> c;
switch(c)
{
case 1 :
p.getdata();
cout << "Entered string is : " << endl;
p.display();
break;
case 2 :
rever();
break;
case 3 :
copy();
break;
case 4 :
p.getdata();
q.getdata();
cout << "ENTERED DATA IS:";
p.display();
cout << endl;
q.display();
(p+q).display();
break;
case 5 :
paly();
break;
}
}
while(c!=6);
}
/*
WELCOME
1.Read & display a string.
2.Reverse a string
3.Copy the string
4.Concatenate the strings
5.To test property Palindrome
6.Exit
Enter ur choice:1
ENTER THE STRING:INDIA
Entered string is :
INDIA
1.Read & display a string.
2.Reverse a string
3.Copy the string
4.Concatenate the strings
5.To test property Palindrome
6.Exit
Enter ur choice:2
WELCOME TO REVERSE THE STRING
ENTER THE STRING:COMPUTER
REVERSED STRING IS: PUTER
1.Read & display a string.
2.Reverse a string
3.Copy the string
4.Concatenate the strings
5.To test property Palindrome
6.Exit
Enter ur choice:3
WELCOME TO COPY THE STRINGENTER THE STRING:PARADISE
THE COPIED STRING IS:PARADISE
1.Read & display a string.
2.Reverse a string
3.Copy the string
4.Concatenate the strings
5.To test property Palindrome
6.Exit
Enter ur choice:4
ENTER THE STRING:Mr.
ENTER THE STRING:RON
ENTERED DATA IS:
Mr.
RON
STRING IS:
Mr.RON
1.Read & display a string.
2.Reverse a string
3.Copy the string
4.Concatenate the strings
5.To test property Palindrome
6.Exit
Enter ur choice:5
WELCOME TO TEST THE PALINDROME PROPERTY
ENTER THE STRING:appa
THE STRING IS PALINDROME.
1.Read & display a string.
2.Reverse a string
3.Copy the string
4.Concatenate the strings
5.To test property Palindrome
6.Exit
Enter ur choice:5
WELCOME TO TEST THE PALINDROME PROPERTY
ENTER THE STRING:new
THE STRING IS NOT PALINDROME.
1.Read & display a string.
2.Reverse a string
3.Copy the string
4.Concatenate the strings
5.To test property Palindrome
6.Exit
Enter ur choice:6
*/
.jpg)
No comments:
Post a Comment