软工实践第二次作业——个人项目实战

1.Fork仓库的Github项目地址

2.PSP表格:

PSP2.1Personal Software Process Stages预估耗时(分钟)实际耗时(分钟)
Planning计划6030
• Estimate• 估计这个任务需要多少时间6030
Development开发600440
• Analysis• 需求分析 (包括学习新技术)120120
• Design Spec• 生成设计文档6030
• Design Review• 设计复审3020
• Coding Standard• 代码规范 (为目前的开发制定合适的规范)3020
• Design• 具体设计12060
• Coding• 具体编码120100
• Code Review• 代码复审6030
• Test• 测试(自我测试,修改代码,提交修改)6060
Reporting报告120150
• Test Repor• 测试报告3060
• Size Measurement• 计算工作量3030
• Postmortem & Process Improvement Plan• 事后总结, 并提出过程改进计划6060
合计780720

3.计算模块接口的设计与实现过程

接收文件查阅资料用ifstream fp(argv[1])

int main(int argc, char* argv[])
{
    int characters =0;//字符个数
    int words = 0;    //单词个数
    int lines = 0;    //有效行数
    char ch;          //文本字符
    int lvalid = 0;   //判断行有效
    int process = 0;  //自动机状态
    ifstream fp(argv[1]);//打开文件
    string word;      //接收单词
    map<string,int> word_count;//构造map容器
    if (!fp)//判断文件是否打开
    {
        cout << "未能成功打开" << argv[1] << ",请检查文件是否存在";
        getchar();//给用户查看错误的时间
        exit(1);
    }
    while (fp.get(ch))//读到文件尾

写result.txt参照资料用ofstream fout("result.txt");

int nSize = word_count.size(),i=1;
    multimap<int, string, greater<int> > mapt;

    for (map<string, int>::iterator it1 = word_count.begin(); it1 != word_count.end(); ++it1)
    {
        mapt.insert(pair<int, string>(it1->second, it1->first));//将word_count输入到mapt
    }
    
    fp.close();
    ofstream fout("result.txt");
    fout << "characters: "<<characters<< endl;
    fout << "words: " << words << endl;
    fout << "lines: " << lines << endl;
    if (nSize <= 10)
    {
        for (map<int, string>::iterator it2 = mapt.begin(); it2 != mapt.end(); ++it2)
        {
            fout << "<" << it2->second << ">: " << it2->first << endl;
        }
    }
    else
    {
        for (map<int, string>::iterator it2 = mapt.begin(); ; ++it2)
        {
            if (i > 10) { break; }
            i++;
            fout << "<" << it2->second << ">: " << it2->first << endl;
        }
    }
    fout.close();

前几天编译原理刚好上了有关自动机的课程,于是这次作业就用上了
1470413-20180913022949943-2010025405.png

switch (process)//无穷自动机
            {
        case 0:if (ch >= 97 && ch <= 122) { word = word + ch; process++; }
               else { word = ""; process = 0; }break;
        case 1:if (ch >= 97 && ch <= 122) { word = word + ch; process++; }
               else { word = ""; process = 0; }break;
        case 2:if (ch >= 97 && ch <= 122) { word = word + ch; process++; }
               else { word = ""; process = 0; }break;
        case 3:if (ch >= 97 && ch <= 122) { word = word + ch; process++; }
               else { word = ""; process = 0; }break;
        case 4:if (ch != ' '&& ch != '\n') { word = word + ch; }
               else { ++word_count[word]; process = 0; word = ""; words++; }break;
            }

4.计算模块接口部分的性能改进

改进思路:由于对C++掌握不精,只想到了按字符读取文件,在翻看资料时又看到说可能一次性读取效果更好,但来不及更改等之后再改

5.计算模块部分单元测试展示

input.txt
1470413-20180913023551941-353724058.png
result.txt
1470413-20180913023609714-418745398.png
测试结果lines为零很让我惊讶,检查代码发现是因为我把换行符的出现视为一行,没有问清是否是以换行符划分行是我准备不足;
不过想不到其他划分行的办法查阅资料也没发现其他方法,下次提早把疑问搞清。

6.计算模块部分异常处理说明

有个异常是因为“”内变量会转化为字符,在老师,同学的帮助下发现了问题换了一种表达ifstream fp(argv[1]);去掉了“”。

收获:发现了自己的许多不足。一次作业就困难重重,离软件开发还有很长的路要走。也收获许多新知识——

参阅资料:

在【统计文件中字符个数】这篇文章中我学会了读写文件;
Map容器的使用总结】教会了我map的使用;
还运用了不太熟练的map以value为准降序排序的方法。

转载于:https://www.cnblogs.com/naxdlr/p/9606663.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值