Assignment 4: Pair project-word frequency statistics

Source: Internet
Author: User
Tags strtok

1. Target
    • Code review Exercises
    • Pairing exercises
    • Writing unit Tests
2. Requirements
    • [ must do 2] read small text file a_tale_of_two_cities.txt or large text file gone_with_the_ Wind.txt, statistics the frequency at which a specified word appears in the text file.
    • command-line format: prompt > Myapp.exe-f filename.txt-w Word (ps:c++ program, Java program output similar)
    • Explain:
      • Option-F means opening a file (filename.txt)
      • The-w option indicates the frequency of the subsequent word (word) in the Open file (filename.txt)

  Knot to object Ji Yang Yang's blog address: http://home.cnblogs.com/u/yangyangji/

  Write your system's GitHub link: https://github.com/yangyangji/ex.2

  Contribution of both parties: 1:1

  Pair programming photos are as follows:

The source code is as follows:

#include <iostream>#include<fstream>#include<cstring>#include<string>using namespacestd;structword{//Define structure Body    intCount;//counterWord (): Str (""), Count (0) {}      stringSTR;//string    Char*p;};voidExchange (Word &word)//function for exchanging words (sort words){      stringTstr =Word.      STR; intTCount =Word.      Count; Word. Str=Str; Word. Count=Count; Str=Tstr; Count=TCount; } Words test[ -];voidLwrCharX[])//uppercase to lowercase{intK =0;  while(X[k]! =' /')    {        if(X[k] >='A'&AMP;&AMP;X[K] <='Z') X[k]= X[k] + +; K++; }}intIdentifyCharA[])//determine if the definition of a word fits{intM= (Strlen (a) >=4)?1:0; intN= (a[0]>='a'&&a[0]<='Z')?1:0; if(!m| |!N)return 0; Else         while(a) { for(intI=1;; i++)           {                 if(! (a[i]>='a'&&a[i]<='Z')||! (a[i]>='0'&&a[i]<='9'))                        return 0; Else                        return 1; }        }}voidSortworddown (Word * words,intSize//sort words in descending order of word occurrence, words Word array, size word number{       for(intI=0; i<size;i++)      {         for(intj=0; J <size-1; j + +)          {             if(Words[j]. count<words[j+1]. Count) {Words[j].exchange (words[j+1]); }          }      }  }  intCounting (CharB[],intNum//Count of Occurrences{ for(intj=0; j<num;j++)    {        if(!strcmp (B,TEST[J].P)) Test[j].count++; Else            return 0; }}intMain () {Charc[ $]; Ifstream Fin ("D:/a_tale_of_two_cities.txt");//get a string from a document     for(intf=0;; f++) Fin>>C[f];    Fin.close (); Cin.Get();    LWR (c); Const Char*delim =", "". '!?";//Split String    Char*Q; intn=0; Q=Strtok (c, Delim);      Sortworddown (words, wcount);  while(q) {if(Identify (q)) {strcpy (test[n].p,q); N++; } q=strtok (Null,delim); } cout<<"Enter the specified word for the frequency of statistics: \ n"; CharR; CIN>>R; intt=0;  while(!STRCMP (Test[n].p,r))//find the specified word{T++; } cout<< TEST[N].P <<":"<< Test[n].count <<'\ n';//outputs the statistical results of the specified word    return 0;}

Experimental results:

Experiment Experience:

As a result of the cooperation, the experimental efficiency has been greatly improved, and their respective areas of expertise have been played.

Assignment 4: Pair project-word frequency statistics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.