17074211张昊 计算与软件工程作业4

作业要求 https://edu.cnblogs.com/campus/jssf/infor_computation17-31/homework/10534
课程目标 完成简单软件功能的开发,会对简单代码进行审核,学会结对编程,和队友搭档一起开发新的功能,会对代码进行单元测试等,分析代码的利用率
参考文献 https://blog.csdn.net/Jiajikang_jjk/article/details/88199213 https://www.cnblogs.com/xinz/archive/2011/08/07/2130332.html
码云 https://gitee.com/zhang_hao17074211/learngit/blob/master/17074211zuoye4

作业1

  • 每个人针对之前两次作业所写的代码,针对要求,并按照代码规范(风格规范、设计规范)要求评判其他学生的程序,同时进行代码复审,要求评价数目不少于8人次,
  • 评价内容直接放在你被评价的作业后面评论中
  • 同时另建立一个博客,将你作的评论的截图或者链接,放在博客中,并在你的博客中谈谈自己的总体看法


作业2
1.实现一个简单而完整的软件工具(中文文本文件人物统计程序):针对小说《红楼梦》要求能分析得出各个人物在每一个章回中各自出现的次数,将这些统计结果能写入到一个csv格式的文件。
2.进行单元测试、回归测试、效能测试,在实现上述程序的过程中使用相关的工具。
3.进行个人软件过程(PSP)的实践,逐步记录自己在每个软件工程环节花费的时间。
4.使用源代码管理系统 (GitHub, Gitee, Coding.net, 等);
5.针对上述形成的软件程序,对于新的文本小说《水浒传》分析各个章节人物出现次数,来考察代码。
结对编程同伴链接:https://www.cnblogs.com/guozhiwei123/p/12619738.html

  #include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Word //声明一个结构体,分别存储单词和对应单词的个数
{
    size_t time;
    char word[230000];
};


void Copy(struct Word *array, FILE *read, const int length);
void Count_for_word(struct Word *array, const int length);

// 函数一
void Copy(struct Word *array, FILE *read, const int length) //该函数的作用是把文本中的单词复制到数组中
{

    char ch, word[230000];
    int i = 0, j;

    while (fscanf(read, "%s", &word) != EOF)
    {
        strcpy(array[i].word, word); // 将word复制到arra[i]中
        ++i;                         //移动数组的下标
    }
    fclose(read);                  // 关闭文件指针
    Count_for_word(array, length); // 调用自定义函数
}

// 函数二
void Count_for_word(struct Word *array, const int length) //统计单词的个数
{
    int i, j;

    for (i = 0; i < length; i++)
    {
        array[i].time = 1;
        for (j = i + 1; j < length; j++)
        {
            if (strcmp(array[i].word, array[j].word) == 0)
            {
                ++array[i].time;            //如果遇到相同的单词,就把相应的结构体部分增加 1
                strcpy(array[j].word, " "); //并把该单词置为空,因为已经读取到数组中了,所以这里改变的是数组的数据,不影响文本数据
            }
        }
    }
    
    printf("the file have %d word

", length);
    
    for (int index = 0; index < length; index++) // 冒泡排序
    {
        for (int temp = 0; temp < length - index-1; temp++)
        {
            // 例如:length = 5
            if (array[temp].time < array[temp + 1].time)
            {
                struct Word word = array[temp];
                array[temp] = array[temp + 1];
                array[temp + 1] = word;
            }
        }
    }


    for (i = 0; i < length; i++)
        if (strcmp(array[i].word, " ") != 0)
        { // 当不相等时候
            //printf("%-5s occurrs  %-3d %s
", array[i].word, array[i].time, ((array[i].time > 1) ? "times" : "time"));
            printf("%-5s:%-3d
", array[i].word, array[i].time);
        }
}

int main(int argc, char *argv[])
{
    char word[230000];
    int length = 0, ch;
    FILE *read;
    struct Word *array;

    if (argc < 2 || argc > 2)
    {
        printf("usage: %s filename
", argv[0]);
        exit(EXIT_FAILURE);
    }
    // 打开文本
    if ((read = fopen(argv[1], "r")) == NULL)
    {
        printf("open file failure
");
        exit(EXIT_FAILURE);
    }
    //
    while (fscanf(read, "%s", &word) != EOF) //测试是否读到文件末尾
    {
        ++length; //统计文本中单词的个数
    }

    rewind(read);                                 //把文件指针置为文本开始的位置,并清除错位信息
    array = malloc(sizeof(struct Word) * length); // 单词的长度动态分配内存
    Copy(array, read, length);                    // 调用自定义函数

    return 0;
}


原文地址:https://www.cnblogs.com/17074211zh/p/12636264.html