Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create a class with at least 2 data members and overload operators << and >>
- #include<iostream>
- #include<string.h>
- using namespace std;
- class lk
- {
- char s[20],a;
- int l;
- public:
- void get_s()
- {
- cout<<"\n Enter String:";
- cin>>s;
- }
- void operator >>(lk a1)
- {
- cout<<strrev(s);
- }
- void operator <<(lk a1)
- {
- l=strlen(s);
- for(int i=0;i<=l;i++)
- {
- if(i%2==0 && i!=(l-1))
- {
- a=s[i+1];
- s[i+1]=s[i];
- s[i]=a;
- i++;
- }
- else
- {
- s[i]=s[i];
- }
- }
- cout<<s;
- }
- };
- int main()
- {
- lk s,a;
- int ch;
- do
- {
- cout<<"\n\n=====> Menu <===== \n";
- cout<<"\n 1. revers string ";
- cout<<"\n 2. interchange of character ";
- cout<<"\n 3. Exit";
- cout<<"\n\n Enter your choice: ";
- cin>>ch;
- switch(ch)
- {
- case 1:
- cout<<"\n Enter 1st String:";
- s.get_s();
- s>>a;
- break;
- case 2:
- cout<<"\n Enter 1st String:";
- s.get_s();
- s<<a;
- break;
- }
- }while(ch<=2 && ch>=1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement