单词,标点统计程序

#include"stdafx.h"
#include
<iostream>
#include
<fstream>
#include
<iomanip>
usingnamespacestd;
structWORDS
...{
charw[30];
inttimes;
}
;
structINTERP
...{
charip;
inttimes;
}
;
intIsAlreadyHaveW(WORDSwords[],charw[],intnW)
...{
inti=0;
for(i=0;i<nW;++i)
...{
if(strcmp(words[i].w,w)==0)
returni;
}

return-1;
}


intIsAlreadyHaveI(INTERPinterp[],charch,intnI)
...{
inti=0;
for(i=0;i<nI;++i)
...{
if(ch==interp[i].ip)
returni;
}

return-1;
}


voidoutPutToXX(ostream&os,WORDSwords[],intnW,intnTW,
INTERPinterps[],
intnI,intnTI)
...{
inti=0;
floatpercent=0;

os
<<endl;
os
<<setw(50)<<"<----StatisticWords---->"<<endl;
os
<<setw(35)<<"Distinct:"<<nW
<<setw(10)<<"Total:"<<nTW<<endl;
os
<<endl;

os
<<setw(10)<<"No."
<<setw(25)<<"Words"
<<setw(10)<<"times"
<<setw(15)<<"percentage"<<endl;

for(i=0;i<nW;++i)
...{
percent
=(words[i].times*100)/nTW;
os
<<setw(10)<<i+1
<<setw(25)<<words[i].w
<<setw(10)<<words[i].times
<<setw(15)<<percent<<"%"<<endl;
}



os
<<endl;
os
<<setw(52)<<"<----StatisticInterpunctions---->"<<endl;
os
<<setw(35)<<"Distinct:"<<nI
<<setw(10)<<"Total:"<<nTI<<endl;
os
<<endl;

os
<<setw(10)<<"No."
<<setw(25)<<"Interps"
<<setw(10)<<"times"
<<setw(15)<<"percentage"<<endl;

for(i=0;i<nI;++i)
...{
percent
=(interps[i].times*100)/nTI;
os
<<setw(10)<<i+1
<<setw(25)<<interps[i].ip
<<setw(10)<<interps[i].times
<<setw(15)<<percent<<"%"<<endl;
}

}

intmain(void)
...{
WORDSwords[
2000];
INTERPinterps[
20];

ifstreamifs;
ifs.open(
"test.txt",ios::in);
if(!ifs)
...{
cout
<<"Openfilefailed!"<<endl;
exit(
1);
}

charw[50];
charch;
inti=0,check=0;
intnWords=0,nTotalW=0;
intnInterps=0,nTotalI=0;
boolinWord=false;

while(!ifs.eof())
...{
ifs.
get(ch);//ch=getc(file);abcdc
if(ch==''||ch==' '||ch=='!'||ch=='?'||ch==','||ch=='.'||ch=='"'||
ch
==':'||ch==';'||ch==''')
...{
if(inWord)
...{
w[i]
='
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值