forked from demon90s/CppStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_5_10.cpp
54 lines (43 loc) · 1.04 KB
/
exercise_5_10.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
/*
* 练习5.10:我们之前实现的统计元音字母的程序存在一个问题:如果元音字母以大写形式出现,不会被统计在内。编写一段程序,既统计元音字母的小写形式,也统计大写形式,也就是说,新程序遇到'a'和'A'都应该递增aCnt的值,以此类推。
*/
// ./exercise_5_10 < data/vowels.txt
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
int main()
{
int aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0;
char ch = 0;
while (cin >> ch) {
switch (ch) {
case 'a':
case 'A':
++aCnt;
break;
case 'e':
case 'E':
++eCnt;
break;
case 'i':
case 'I':
++iCnt;
break;
case 'o':
case 'O':
++oCnt;
break;
case 'u':
case 'U':
++uCnt;
break;
}
}
cout << "Number of vowel a: " << aCnt << endl;
cout << "Number of vowel e: " << eCnt << endl;
cout << "Number of vowel i: " << iCnt << endl;
cout << "Number of vowel o: " << oCnt << endl;
cout << "Number of vowel u: " << uCnt << endl;
return 0;
}