Advertisement
ptrawt

259201 Lab9.2

Nov 4th, 2014
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     string str;
  10.     int vc[5] = {0,0,0,0,0} ; //vowel counter
  11.    
  12.     cout<<"Enter string: ";
  13.     getline(cin,str);
  14.     cout<<"Input size: "<<str.size()<<endl;
  15.    
  16.     const char * tstr = str.c_str();
  17.     char rstr[str.size()],cstr[str.size()];
  18.    
  19.     int j = 0;
  20.     for(int i = str.size()-1 ; i >= 0 ; i--)
  21.     {
  22.         rstr[i] = tstr[j++];
  23.         switch(rstr[i])
  24.         {
  25.             case 'A':
  26.             case 'a':
  27.                 vc[0]++;
  28.                 break;
  29.             case 'E':
  30.             case 'e':
  31.                 vc[1]++;
  32.                 break;
  33.             case 'I':
  34.             case 'i':
  35.                 vc[2]++;
  36.                 break;
  37.             case 'O':
  38.             case 'o':
  39.                 vc[3]++;
  40.                 break;
  41.             case 'U':
  42.             case 'u':
  43.                 vc[4]++;
  44.                 break;
  45.         }
  46.     }
  47.     cout<<"#Vowel in input string: A="<<vc[0]<<", E="<<vc[1]<<", I="<<vc[2]<<", O="<<vc[3]<<", U="<<vc[4]<<endl;
  48.     cout<<"Reverse string: "<<rstr<<endl;
  49.     cout<<"Concatenated string : "<<strcat(rstr,strcpy(cstr,tstr));
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement