Advertisement
chrlwrd

Programming Challenge 1

Feb 22nd, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cctype>
  4. using namespace std;
  5.  
  6. void separate(char *);
  7. void sort(char *, int );
  8.  
  9. char in[100], vOut[100], cOut[100];
  10.  
  11. int main()
  12. {
  13.     cout << "Enter a word: ";
  14.     cin.getline(in, 100);
  15.  
  16.     separate(in);
  17.  
  18.     sort(vOut, 1);
  19.     sort(cOut, 0);
  20.  
  21.     cout << endl << "Vowels: " << vOut << endl;
  22.     cout << "Consonants: " << cOut << endl << endl;
  23.  
  24.     system("PAUSE");
  25.     system("cls");
  26.     main();
  27. }
  28.  
  29. void separate(char * input)
  30. {
  31.     int vCount = 0, cCount = 0, length = strlen(input);
  32.  
  33.     for(int i = 0; i < length; i++)
  34.     {
  35.         if( input[i] == 'a' || input[i] == 'A' ||
  36.             input[i] == 'e' || input[i] == 'E' ||
  37.             input[i] == 'i' || input[i] == 'I' ||
  38.             input[i] == 'o' || input[i] == 'O' ||
  39.             input[i] == 'u' || input[i] == 'U' )
  40.         {
  41.             vOut[vCount] = tolower(input[i]);
  42.             vCount++;
  43.         }
  44.         else if(isalpha(input[i]) == 0)
  45.         {
  46.             // ignore characters that aren't letters
  47.         }
  48.         else
  49.         {
  50.             cOut[cCount] = tolower(input[i]);
  51.             cCount++;
  52.         }
  53.     }
  54. }
  55.  
  56. void sort(char * input, int isVowel)
  57. {
  58.     int length = strlen(input);
  59.  
  60.     for(int i = 0; i < length; i++)
  61.     {
  62.         for(int j = 0; j < length-1; j++)
  63.         {
  64.             if(input[j + 1] < input[j])
  65.             {
  66.                 char temp = input[j + 1];
  67.                 input[j + 1] = input[j];
  68.                 input[j] = temp;
  69.             }
  70.         }
  71.     }
  72.  
  73.     if(isVowel == 1)
  74.     {
  75.         for(int i = 0; i < length; i++)
  76.         {
  77.             vOut[i] = input[i];
  78.         }
  79.     }
  80.     else
  81.     {
  82.         for(int i = 0; i < length; i++)
  83.         {
  84.             cOut[i] = input[i];
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement