1.GitHub地址
https://github.com/tsfdssm/WC
2.PSP表格
PSP2.1 | PSP 阶段 | 预估耗时 (分钟) | 实际耗时 (分钟) |
---|---|---|---|
Planning | 计划 | 30 | 60 |
· Estimate | · 估计这个任务需要多少时间 | 600 | 900 |
Development | 开发 | 600 | 300 |
· Analysis | · 需求分析 | 30 | 30 |
· Design Spec | · 生成设计文档 | 20 | 30 |
· Design Review | · 设计复审 | 10 | 30 |
· Coding Standard | · 代码规范 | 300 | 120 |
· Design | · 具体设计 | 20 | 90 |
· Coding | · 具体编码 | 300 | 720 |
· Code Review | · 代码复审 | 60 | 60 |
· Test | · 测试 | 20 | 180 |
Reporting | 报告 | 30 | 40 |
· Test Report | · 测试报告 | 20 | 20 |
· Size Measurement | · 计算工作量 | 5 | 10 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 10 | 10 |
合计 | 1800 | 1680 |
3.WordCount需求说明
WordCount的需求可以概括为:对程序设计语言源文件统计字符数、单词数、行数,统计结果以指定格式输出到默认文件中,以及其他扩展功能,并能够快速地处理多个文件。
可执行程序命名为:wc.exe,该程序处理用户需求的模式为:
wc.exe [parameter] [input_file_name]
存储统计结果的文件默认为result.txt,放在与wc.exe相同的目录下。
4.解题思路
1.首先进行需求分析。
2.然后根据相应的需求进行初步设计。然而由于本人能力有有限,最初想要实现的几个比较难的功能一个都没有实现,我真的好菜。。。
3.由于我分析得比较简单,没有对需求做出更加深入的思考。所以代码编写得也比较乱。主要是每个功能由一个函数实现。
大致如下:
1 int _c(char*); 2 3 int _w(char*); 4 5 int _l(char*); 6 7 bool _o(char*); 8 9 bool _s(char*); 10 11 bool _a(char *); 12 13 bool _e(char*); 14 15 void _x();
5.代码分析
(1)实现-c功能。
1 int WordCount::_c(char * file)
(2)实现-w功能,这个是通过检测字符是否为空格,回车,逗号等以及其后的字符也是否为回车,空格,逗号来判断字符数量的。
int WordCount::_w(char *file) { //// ifstream fin; int word = 1; fin.open(file); if (!fin.is_open()) //检测文件是否成功打开 { cerr << "Could not open" << file << endl; fin.clear(); fin.close(); return - 1; } while(!fin.eof()) { char cw = fin.get(); char cp = fin.peek(); if (!((cw == ' ')|| (cw == '\0')||(cw == '\t' )||( cw == '\n') || (cw == ','))) { if((cp == ' ') || (cp == '\0') || (cp == '\t') || (cp == '\n') || (cp == ',')) { word++; } } } fin.clear(); fin.close(); return word;//返回计数值 }
(3)实现-l功能。
int WordCount::_l(char * file)
(4)实现-o功能。其实-o功能还需要其他代码才能实现。
1 bool WordCount::_o(char *file)
(5)实现-s功能。
1 bool WordCount::_s(char *file)
(6)实现-a功能。
1 bool WordCount::_a(char *file)
(7)实现-e功能:
1 bool WordCount::_e(char *stoplistfile)
(8)实现-x功能:
1 void WordCount::_x() 2 { 3 WinExec("WordCountUI.exe", SW_NORMAL); 4 }
6.测试
如图这只是在控制台上进行简单测试。这样效率较高.实际在文件中的输出与之类似,不在赘述。
由于时间较紧,关于禁用词表的功能还有部分未能实现,还望见谅。
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10‘)
7.参考的相关资料及网址:
https://wenku.baidu.com/view/7cb4e4096fdb6f1aff00bed5b9f3f90f76c64df0.html
https://www.cnblogs.com/collectionne/p/6815924.html
http://blog.youkuaiyun.com/u011543018/article/details/50724883
http://blog.youkuaiyun.com/cc514981717/article/details/52130621
http://blog.youkuaiyun.com/qq_15437667/article/details/52215917
https://www.cnblogs.com/collectionne/p/6815924.html
https://www.cnblogs.com/tinaluo/p/6824674.html