1.Fork仓库的Github项目地址
2.PSP表格:
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 60 | 30 |
• Estimate | • 估计这个任务需要多少时间 | ||
Development | 开发 | 600 | 440 |
• Analysis | • 需求分析 (包括学习新技术) | 120 | |
• Design Spec | • 生成设计文档 | ||
• Design Review | • 设计复审 | 20 | |
• Coding Standard | • 代码规范 (为目前的开发制定合适的规范) | ||
• Design | • 具体设计 | ||
• Coding | • 具体编码 | 100 | |
• Code Review | • 代码复审 | ||
• Test | • 测试(自我测试,修改代码,提交修改) | ||
Reporting | 报告 | 150 | |
• Test Repor | • 测试报告 | ||
• Size Measurement | • 计算工作量 | ||
• Postmortem & Process Improvement Plan | • 事后总结, 并提出过程改进计划 | ||
合计 | 780 | 720 |
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();
前几天编译原理刚好上了有关自动机的课程,于是这次作业就用上了

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
result.txt
测试结果lines为零很让我惊讶,检查代码发现是因为我把换行符的出现视为一行,没有问清是否是以换行符划分行是我准备不足;
不过想不到其他划分行的办法查阅资料也没发现其他方法,下次提早把疑问搞清。
6.计算模块部分异常处理说明
有个异常是因为“”内变量会转化为字符,在老师,同学的帮助下发现了问题换了一种表达ifstream fp(argv[1]);去掉了“”。
收获:发现了自己的许多不足。一次作业就困难重重,离软件开发还有很长的路要走。也收获许多新知识——
参阅资料:
在【统计文件中字符个数】这篇文章中我学会了读写文件;
【Map容器的使用总结】教会了我map的使用;
还运用了不太熟练的map以value为准降序排序的方法。