软工结对2

031602204 陈加伟 (博客地址:https://www.cnblogs.com/Tony-chenjw/p/9769802.html

031602226 林淇(博客地址:https://www.cnblogs.com/q1093797687/p/9769781.html


一、具体分工

陈加伟:自定义输入输出文件,词组词频统计功能,自定义词频统计输出
林淇:加入权重的词频统计,博客

二、PSP

PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟)
Planning 计划 60 50
· Estimate · 估计这个任务需要多少时间 30 30
Development 开发 200 250
· Analysis · 需求分析 (包括学习新技术) 90 90
· Design Spec · 生成设计文档 30 40
· Design Review · 设计复审 20 20
· Coding Standard · 代码规范 (为目前的开发制定合适的规范) 20 30
· Design · 具体设计 200 250
· Coding · 具体编码 1000 1100
· Code Review · 代码复审 90 80
· Test · 测试(自我测试,修改代码,提交修改) 100 120
Reporting 报告 30 40
· Test Report · 测试报告 20 30
· Size Measurement · 计算工作量 10 15
· Postmortem & Process Improvement Plan · 事后总结, 并提出过程改进计划 30 50
合计 1840 2195

三、解题思路描述与设计实现说明

爬虫使用

使用了现有的爬虫工具八爪鱼实现。该工具可以快速的爬取指定的网页信息,但爬取后的数据要进一步处理为指定格式。

Pic

代码组织与内部实现设计

Pic

wordcount()

Pic

wordmax()

Pic

四、关键代码解释

自定义输入输出文件

int main(int c, char **v)
{
    if (c < 2)
        return 0;

    int i = 1;

    while (i < c)
    {
        vv = v[i];
        if (vv == "-i")
        {
            //传v[i+1],它是输入路径
            txi = v[i + 1];
            i += 2;
            continue;
        }
        if (vv == "-o")
        {
            //传v[i+1],它是输出路径
            txo = v[i + 1];
            i += 2;
            continue;
        }
        if (vv == "-w")
        {
            s = v[i + 1];
            //传v[i+1],它是权重
            if (s == "1")
                bo = 1;
            i += 2;
            continue;
        }
        if (vv == "-m")
        {
            //传v[i+1]它是词数
            m = atoi(v[i + 1]);
            i += 2;
            continue;
        }
        if (vv == "-n")
        {
            //传v[i+1],它是输出个数
            num = atoi(v[i + 1]);
            i += 2;
            continue;
        }
    }

-m 参数设定统计的词组长度


void wordmax(char *tx, string txo, int num, int m)
{
    FILE *fp;
    fopen_s(&fp, tx, "r");
    ofstream outf(txo, ios::app);

    char ch = getc(fp);
    int i = 0, j, ct;
    wd max[100];

    while (!feof(fp))
    {
        ct = 0;
        temps = "";
        while (ch != ':')
            ch = getc(fp);
        while (!ifchar(ch))
            ch = getc(fp);
        while (1)
        {
            if (ch == 10 || ch == EOF)//读到回车,文末
            {
                if (ifword(temps))
                {
                    str[ct] = temps;
                    temps = "";
                    for (int j = 0; j <= ct; j++)//temps置为前面的累加
                        temps = temps + str[j];
                    start(temps, m);
                }
                else//temps是非法单词
                {
                    temps = "";
                    if (ct >= m)//前面的长度大于指定数m
                    {
                        for (int j = 0; j <= ct; j++)//temps置为前面的累加*********<=ct
                            temps = temps + str[j];
                        start(temps, m);
                    }
                }
                break;
            }
            if (temps.size() == 0)
            {
                temps = temps + ch;
                ch = getc(fp);
            }
            else if ((ifchar(temps[temps.size() - 1]) == 0) && ifchar(ch))//遇到当前是字母数字,上一个是分隔符,结束读取
            {
                if (ifword(temps))
                {
                    str[ct] = temps;
                    ct++;
                    temps = "";
                }
                else//temps是非法单词
                {
                    temps = "";
                    if (ct >= m)//前面的长度大于指定数m
                    {
                        for (int j = 0; j <= ct; j++)//temps置为前面的累加*********<=ct
                            temps = temps + str[j];
                        start(temps, m);

                    }
                    ct = 0;
                    temps = "";
                }
            }
            temps = temps + ch;
            ch = getc(fp);
        }
    }
    sor(word, n);

    for (i = 0; i < num; i++)//初始化前num名
    {
        max[i] = word[i];
    }

    for (j = 0; j < num; j++)//前num名排序 
    {
        for (i = 0; i < num - j - 1; i++)
        {
            if (max[i].frq < max[i + 1].frq)
            {
                swap(max[i], max[i + 1]);
            }
        }
    }

    for (i = 10; i < n; i++)//找后面的数 
    {
        if (max[9].frq < word[i].frq)//比最小的还大 
        {
            int a = 8;
            while (max[a].frq < word[i].frq&&a >= 0)
            {
                a--;//定位到第一个比自己大的word
            }

            for (j = 9; j > a + 1; j--)
            {
                max[j] = max[j - 1];//前面的数后移一位 
            }
            if (a < 0)//说明word[i]比max[0]大
                max[0] = word[i];
            else
                max[j] = word[i];
        }
    }

    for (int i = 0; i < num; i++)
    {
        if (max[i].s.length() == 0)
            continue;
        outf << "<" << max[i].s << ">" << ":" << max[i].frq << endl;
    }
    outf.close();
}

性能分析与改进

展示性能分析图和程序中消耗最大的函数

Pic
Pic

贴出Github的代码签入记录

Pic
Pic

遇到的困难及解决方法

问题描述

做过哪些尝试

是否解决

有何收获

评价你的队友

值得学习的地方

需要改进的地方

学习进度条

第一周 新增代码(行) 累计代码(行) 本周学习耗时(小时)) 累计学习耗时(小时) 重要成长
1 0 0 10 10 学会了Axure的基本使用

猜你喜欢

转载自www.cnblogs.com/Tony-chenjw/p/9769802.html