结对编程

git地址 git地址
结对成员 宁晓静
结对成员学号 201831061202

PSP表格

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

设计实现

设计思路

主要代码

1.打开文件并判断是否成功

ifstream fp(filename, ios::in);
if (!fp)//判断文件是否打开
	{
		cout << "未能成功打开" << filename << ",请检查文件是否存在";
		getchar();
		exit(1);
	}

2.英文只要字母相同,无论大小写都算作一个单词,所以首先将所有大写字母全部转换为小写

void change(char a)
{
	if (a >= 65 && a <= 90) { a += 32; }//大写转为小写
}

3.判断是否为空行

if (ch != ' ' && ch != '\n') { isline = 1; }//标记为非空行

4.词频统计(使用无穷自动机)

switch (process)
		{
		case 0:if (ch >= 97 && ch <= 122) { word = word + ch; nap++; }
			   else { word = ""; nap = 0; }break;
		case 1:if (ch >= 97 && ch <= 122) { word = word + ch; nap++; }
			   else { word = ""; nap = 0; }break;
		case 2:if (ch >= 97 && ch <= 122) { word = word + ch; nap++; }
			   else { word = ""; nap = 0; }break;
		case 3:if (ch >= 97 && ch <= 122) { word = word + ch; nap++; }
			   else { word = ""; nap = 0; }break;
                //第四位仍是字母则记为单词
		case 4:if (ch != ' ' && ch != '\n' && ch != '!' && ch != '.' && ch != ',' && ch != ':' && ch != '(' && ch != ')' && ch!='?')
		{
			word = word + ch;
		}
			   else { ++word_count[word]; nap = 0; word = ""; words++; }break;
		}

5.统计行数
因为代码中设定为读到换行符才记为行数+1,而文档的最后一行无换行符,所以设定输出结果为(lines+1)

//非空行且读到换行符则行数+1
if (ch == '\n')
		{
			if (isline == 1) { lines++; }
			isline = 0;//判断标记置0
		}

6.构造容器
对于这部分内容完全是全新的知识,学习与应用上都花费了大量时间
map的迭代器起到了很大的作用

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

	for (map<string, int>::iterator it1 = word_count.begin(); it1 != word_count.end(); ++it1)
	{
		mapw.insert(pair<int, string>(it1->second, it1->first));//将word_count输入到mapw
	}

代码复审

我们使用了源自网络的编程规范:编程规范
在代码整合与复审过程中首先发现了关于代码结构的一系列问题,因为在最初对于代码规划上的一些小问题,使代码读起来不是足够条理,虽然不影响运行,但可读性不高。
其次是变量命名的问题,因为经常使用如a、b之类的简单变量名,使代码阅读起来不够清晰。
最终我们经过讨论与整合修改了上述问题。

性能分析

异常处理

当找不到文件时则提示用户并退出程序

测试

分别对几行句子及大量文章进行测试,结果全部正确

结对过程

有一个共同完成的伙伴,可以共同学习新的内容,不仅遇到问题可以交流讨论,更多了一个人督促自己,总体来说是1+1>2的