C++ Primer(第5版) 练习 5.12
练习 5.12 修改统计元音字母的程序,使其也能统计空格、制表符和换行符的数量。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块
/*************************************************************************
> File Name: ex5.11.cpp
> Author:
> Mail:
> Created Time: Sun 11 Feb 2024 12:48:36 PM CST
************************************************************************/
#include<iostream>
#include<vector>
using namespace std;
int main(){
unsigned aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0, space = 0, tab = 0, newli
string ch;
while(getline(cin, ch)){
++newline;
for(auto s = ch.begin(); s != ch.end(); s++){
switch(*s){
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;
case ' ': ++space; break;
case '\t': ++tab; break;
default: break;
}
}
}
cout<<"Number of vowel a, A:\t"<<aCnt<<endl;
cout<<"Number of vowel e, E:\t"<<eCnt<<endl;
cout<<"Number of vowel i, I:\t"<<iCnt<<endl;
cout<<"Number of vowel o, O:\t"<<oCnt<<endl;
cout<<"Number of vowel u, U:\t"<<uCnt<<endl;
cout<<"Number of space:\t"<<space<<endl;
cout<<"Number of tab:\t\t"<<tab<<endl;
cout<<"Number of newline:\t"<<newline<<endl;
return 0;
}