-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExer05_12.cpp
58 lines (58 loc) · 1.48 KB
/
Exer05_12.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <cctype>
using std::cout;
using std::cin;
using std::endl;
int main()
{
unsigned aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0, twoChCnt = 0;
char chNow, chLast = '\0';
// If we just count the number of vowels or "ff", "fl", "fi", it's easy.
// If we have to count the number of vowels and "ff", "fl", "fi", we have to
// cope with characters carefully, because the vowel 'i' appears in both
// cases.
while(cin >> chNow)
{
switch(chNow){
case 'a':
case 'A':
++aCnt;
break;
case 'e':
case 'E':
++eCnt;
break;
case 'i':
++iCnt;
if(chLast == 'f')
++twoChCnt;
break;
case 'I':
++iCnt;
break;
case 'o':
case 'O':
++oCnt;
break;
case 'u':
case 'U':
++uCnt;
break;
case 'f':
case 'l':
if(chLast == 'f')
++twoChCnt;
break;
default:
break;
}
chLast = chNow;
}
cout << "Number of vowel a: \t" << aCnt << endl;
cout << "Number of vowel e: \t" << eCnt << endl;
cout << "Number of vowel i: \t" << iCnt << endl;
cout << "Number of vowel o: \t" << oCnt << endl;
cout << "Number of vowel u: \t" << uCnt << endl;
cout << "Number of ff, fl and fi: " << twoChCnt << endl;
return 0;
}