#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]='
735

被折叠的 条评论
为什么被折叠?



