类的学习

wariob wariob 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream.h>
#include "String.h"
int main()
{
int aCnt =0, eCnt = 0, iCnt=0,uCnt=0,
theCnt=0, itCnt=0,wdCnt=0,notVowel=0;
//为了使用operator==(const char*)
//我们并不定义The("the"),TI("It")
String buf,the("the"),it("it");
//调用operator>>(istream&,String&)
while( cin >> buf ){
++wdCnt;

//调用operator<<(ostream&,const String&)
cout<<buf<< ' ';
if ( wdCnt%12==0 )
cout <<endl;
//调用String::operator==(const String&) and
// String::operator==(const char*);
if ( buf ==the || buf == "The" )
++theCnt;
else
if (buf == the || buf == "The" )
++itCnt;

//调用String::size()
for( int ix =0; ix < buf.size(); ++ix )
{
//调用String::operator[](int)
switch( buf[ix] )
{
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;
default:
++notVowel;
break;
}
}
}
//调用operator<<( ostream&, const String& )
cout << "\n\n"
<<"Words read: " << wdCnt <<"\n\n"
<<"the/The: " <<theCnt <<'\n'
<<"it/It: " <<itCnt <<"\n\n"
<<"non-vowels read: " << notVowel << "\n\n"
<<"a: "<<aCnt<<'\n'
<<"e: "<<eCnt<<'\n'
<<"i: "<<iCnt<<'\n'
<<"o: "<<oCnt<<'\n'
<<"u: "<<uCnt<<endl;
}


...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
wariob
新手乐园 33,315 成员 41,769 内容