Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cctype>
- using namespace std;
- void separate(char *);
- void sort(char *, int );
- char in[100], vOut[100], cOut[100];
- int main()
- {
- cout << "Enter a word: ";
- cin.getline(in, 100);
- separate(in);
- sort(vOut, 1);
- sort(cOut, 0);
- cout << endl << "Vowels: " << vOut << endl;
- cout << "Consonants: " << cOut << endl << endl;
- system("PAUSE");
- system("cls");
- main();
- }
- void separate(char * input)
- {
- int vCount = 0, cCount = 0, length = strlen(input);
- for(int i = 0; i < length; i++)
- {
- if( input[i] == 'a' || input[i] == 'A' ||
- input[i] == 'e' || input[i] == 'E' ||
- input[i] == 'i' || input[i] == 'I' ||
- input[i] == 'o' || input[i] == 'O' ||
- input[i] == 'u' || input[i] == 'U' )
- {
- vOut[vCount] = tolower(input[i]);
- vCount++;
- }
- else if(isalpha(input[i]) == 0)
- {
- // ignore characters that aren't letters
- }
- else
- {
- cOut[cCount] = tolower(input[i]);
- cCount++;
- }
- }
- }
- void sort(char * input, int isVowel)
- {
- int length = strlen(input);
- for(int i = 0; i < length; i++)
- {
- for(int j = 0; j < length-1; j++)
- {
- if(input[j + 1] < input[j])
- {
- char temp = input[j + 1];
- input[j + 1] = input[j];
- input[j] = temp;
- }
- }
- }
- if(isVowel == 1)
- {
- for(int i = 0; i < length; i++)
- {
- vOut[i] = input[i];
- }
- }
- else
- {
- for(int i = 0; i < length; i++)
- {
- cOut[i] = input[i];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement