• 软件工程作业------分析文本文档,统计出现频率最多的十个单词


    在上周一软件工程的王老师给我们布置了作业,由于我们课程比较满,所以只能把敲代码的时间挪到了周末。但自己在敲代码之前利用零散的时间构造自己程序的结构算法。

     1.分析文本文档,首先要成功的打开文本文档。即要用到文件流的输入输出。头文件#include<fstream>和函数fopen(),getc()等

    int wenjianopen(FILE *fp)
    {
     fp=fopen("yingyu.txt","r");
     if(fp==NULL)
      cout<<"文件打开错误,请检验。"<<endl;
     return 0;
    }

    2.文件创建以后需要读入文件中的英文单词。在读入过程中如果是单词就录入结构体ciyu[30]中,方便以后进行比较和统计。

    struct yingyu
    {
     string danci;
     int count;
    }ciyu[40],d;

    3。文本文档的内容:

    My father was a self-taught mandolin player. He was one of the best string instrument players in our town. He could not read music, but if he heard a tune a few times, he could play it. When he was younger, he was a member of a small country music band. They would play at local dances and on a few occasions would play for the local radio station. He often told us how he had auditioned and earned a position in a band that featured Patsy Cline as their lead singer. He told the family that after he was hired he never went back. Dad was a very religious man. He stated that there was a lot of drinking and cursing the day of his audition and he did not want to be around that type of environment.

    4.在比较过程中利用选择比较法进行比较:

     for(int p=0;p<N;p++)
     {
      q=p;
      for(int r=p+1;r<N;r++)
       if(ciyu[q].count<ciyu[r].count)
        q=r;
      if(q!=p)
      {
       d.count=ciyu[q].count;
       ciyu[q].count=ciyu[p].count;
       ciyu[p].count=d.count;
       d.danci=ciyu[q].danci;
       ciyu[q].danci=ciyu[p].danci;
       ciyu[p].danci=d.danci;
      }

    5.运行结果:

  • 相关阅读:
    python学习之路-10 网络编程之进阶
    python学习之路-9 socket网络编程
    使用cx_Freeze 将python3代码打包成.exe程序
    如何在已经存在python2的linux环境上安装python3
    python学习之路-8 面向对象之进阶
    python学习之路-7 模块configparser/xml/shutil/subprocess以及面向对象初级入门
    java mybatis XML文件中大于号小于号转义
    java dom4j写入XML
    notepad++ 行末尾添加指定字符
    JQ 动态加载多选框--随记
  • 原文地址:https://www.cnblogs.com/moshang-zjn/p/3577755.html
Copyright © 2020-2023  润新知