#include " stdafx.h " #include < iostream > #include < fstream > #include < iomanip > using namespace std; struct WORDS ... { char w[30]; int times;} ; struct INTERP ... { char ip; int times;} ; int IsAlreadyHaveW(WORDS words[], char w[], int nW) ... { int i=0; for(i=0; i<nW; ++i) ...{ if(strcmp(words[i].w, w)==0) return i; } return -1;} int IsAlreadyHaveI(INTERP interp[], char ch, int nI) ... { int i=0; for(i=0; i<nI; ++i) ...{ if(ch == interp[i].ip) return i; } return -1;} void outPutToXX(ostream & os,WORDS words[], int nW, int nTW, INTERP interps[], int nI, int nTI) ... { int i=0; float percent = 0; os << endl; os << setw(50) << "<----Statistic Words---->" << 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) << "<----Statistic Interpunctions---->" << 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; }} int main( void ) ... { WORDS words[2000]; INTERP interps[20]; ifstream ifs; ifs.open("test.txt",ios::in); if(!ifs) ...{ cout << "Open file failed!" << endl; exit(1); } char w[50]; char ch; int i=0, check=0; int nWords=0, nTotalW = 0; int nInterps=0, nTotalI = 0; bool inWord = false; while(!ifs.eof()) ...{ ifs.get(ch);//ch = getc(file); abc dc if(ch == ' '|| ch == ' '|| ch == '!' || ch == '?' || ch == ',' || ch == '.'||ch=='"'|| ch==':'||ch == ';'||ch==''') ...{ if(inWord) ...{ w[i] = '