Advertisement
Aniket_Goku

p5

Nov 4th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. //Create a class with at least 2 data members and overload operators << and >>
  2. #include<iostream>
  3. #include<string.h>
  4. using namespace std;
  5. class lk
  6. {
  7.     char s[20],a;
  8.     int l;
  9.     public:
  10.     void get_s()
  11.     {
  12.         cout<<"\n Enter String:";
  13.         cin>>s;
  14.     }
  15.     void operator >>(lk a1)
  16.     {
  17.         cout<<strrev(s);
  18.     }
  19.     void operator <<(lk a1)
  20.     {
  21.         l=strlen(s);
  22.        
  23.         for(int i=0;i<=l;i++)
  24.         {
  25.             if(i%2==0  && i!=(l-1))
  26.             {
  27.                 a=s[i+1];
  28.                 s[i+1]=s[i];
  29.                 s[i]=a;
  30.                 i++;
  31.             }
  32.             else
  33.             {
  34.                 s[i]=s[i];
  35.             }
  36.         }
  37.         cout<<s;
  38.     }
  39. };
  40. int main()
  41. {
  42.     lk s,a;
  43.     int ch;
  44.         do
  45.     {
  46.  
  47.         cout<<"\n\n=====> Menu <===== \n";
  48.         cout<<"\n 1. revers string ";
  49.         cout<<"\n 2. interchange of character ";
  50.         cout<<"\n 3. Exit";
  51.         cout<<"\n\n Enter your choice: ";
  52.         cin>>ch;
  53.         switch(ch)
  54.         {
  55.             case 1:
  56.                 cout<<"\n Enter 1st String:";
  57.                 s.get_s();
  58.                 s>>a;
  59.                 break;
  60.             case 2:
  61.                 cout<<"\n Enter 1st String:";
  62.                 s.get_s();
  63.                 s<<a;
  64.             break;
  65.         }  
  66. }while(ch<=2 && ch>=1);
  67. return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement