单词,标点统计程序

#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] 
= '
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值