21.Consider the following class mystring Class mystring { char str [100]; Public: // methods }; Overload operator “!” to reverse the case of each alphabet in the string.


#include<iostream.h>
#include<conio.h>
#include<string.h>
class mystring
{
char str[20];
public:
void operator!();
void get()
{
cout<<“\nEnter String: “;
cin>>str;
}
void disp()
{
cout<<str;
}
};
void mystring::operator!()
{
for(int i=0;str[i]!=”;i++)
{
if(str[i]>=65&&str[i]<=96)
{
str[i]=str[i]+32;
}
else if(str[i]>=97&&str[i]<=122)
{
str[i]=str[i]-32;
}
}
cout<<“\n\nReverse Case String is: “<<str;
}
void main()
{
mystring s1;
clrscr();
s1.get();
cout<<“\n\nString is: “;
s1.disp();
!s1;
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s