PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟 |
Planning | 计划 | 120 | 180 |
· Estimate | · 估计这个任务须要多少时间 | 1440 | 1000 |
Development | 开发 | 720 | 600 |
· Analysis | · 需求分析 (包括学习新技术) | 300 | 240 |
· Design Spec | · 生成设计文档 | 120 | 100 |
· Design Review | · 设计复审 (和同事审核设计文档) | 50 | 89 |
· Design Review | · 代码规范 (为目前的开发制定合适的规范) | 60 | 30 |
· Design | · 具体设计 | 250 | 300 |
· Coding | · 具体编码 | 740 | 600 |
· Code Review | 代码复审 | 180 | 120 |
Test | · 测试(自我测试,修改代码,提交修改) | 300 | 360 |
Reporting | 报告 | 60 | 45 |
· Test Report | · 测试报告 | 60 | 55 |
· Size Measurement | · 计算工做量 | 50 | 30 |
· Postmortem & Process Improvement Plan | · 过后总结, 并提出过程改进计划 | 45 | 30 |
合计 | 1000 | 1200 |
对这个问题的大体解题阶段:
拿到这个题目的时候,由于他要实现的功能相对较多。因此,我先对每个要实现的功能设计了函数。
因此,我先对每个要实现的功能设计了函数。下面是一些我认为相对来讲比较麻烦的功能的实现:
一共两个类: 基类:
class word_count { public: void f_open();/*打开文件函数*/ void count_acill();/*统计文件中出现的acill 码*/ void count_aphabet();/*统计文件中出现的字母*/ void count_Enum();/*统计文件中出现的字母*/ void count_seperetors();/*统计文件中出现的分割符号*/ void count_line();/*存储文件中的每一行的字符串*/ void display_1(); protected: ifstream f_in; private: int acill; int aphabate; int Enum; int seperetors; string line_count[MAX]; string line_count_all[MAX]; };
继承类:node
class word_count2 :public word_count { public : void read_str(); void store_str(string s); void display(); void count_limit(); void ruin_node(); private: count_str *first, *rear; };
写了一点代码,我发现对于像我如今这个阶段。完整的写一段代码花费时间更多的是在后面的修改代码上面。缘由是:首先,本身写代码用的算法都是已经存在,没有说本身设计一个算法去写一段代码。其次,本身对不少语法不熟悉,每次编译的时候没有问题可是运行就会出错。最后,对整段代码的分析不到位,得不到本身想要的结果。 此次写代码,在写函数统计文件中出现的频数最大的10个字符串的时,就遇到了一个让我很恼火的问题。在这里我也花费了不少的时间去修改。可是最后我仍是放弃了重写一段代码来代替他。 未修改前的思路:
修改后的思路:
通过了此次同伴复审后,我发觉有一个同伴来审查本身写的代码会提升本身写代码的效率。 ###(1)提升本身代码的运行可信度。 此次写函数统计指定字符的时候,我忘记了"123file"这一类不是单词,不能被写入。 起始代码是这样的:
void word_count2::read_str() { char ch;//收集每个文件中字符 string str_1;//记录每个规定的字符 long pos;//记录f_in的位置 int fir = 0;//判断第一个字符是否为字母 f_in.clear(); f_in.seekg(0, ios::beg); while (!f_in.eof()) { int read=0; f_in.get(ch); read++; int k; f_in.seekg(pos); //f_in.get(ch); for ( k = 1; k < 4; k++) { read++; f_in.get(ch); if ( ch<'A' || (ch > 'Z'&& ch < 'a') || ch>'z' ) break; } if (k == 4) { f_in.get(ch); while (('a' <= ch && 'z' >= ch) || ('A' <= ch && 'Z' >= ch)|| ( '0' <= ch && ch <= '9')) { f_in.get(ch); read++; } pos = f_in.tellg(); f_in.seekg(pos - read); getline(f_in, str_1, ch); store_str(str_1); f_in.seekg(pos); } } } }
通过个人好伙伴的提醒我就有修改了代码,以下:
void word_count2::read_str() { char ch;//收集每个文件中字符 string str_1;//记录每个规定的字符 long pos;//记录f_in的位置 int fir = 0;//判断第一个字符是否为字母 f_in.clear(); f_in.seekg(0, ios::beg); while (!f_in.eof()) { f_in.get(ch); fir++; if (('a' <= ch && 'z' >= ch) || ('A' <= ch && 'Z' >= ch)) { int read=1;//记录规定字符创的长度。 //-------------------------------------------------->增长代码 if (fir == 1) { pos = f_in.tellg(); } else { pos = f_in.tellg(); f_in.seekg(pos-1);//获得上一个字符 f_in.get(ch); } if (('0' <= ch && ch <= '9') || ch== '" ') { f_in.seekg(pos); f_in.get(ch); while (('a' <= ch && 'z' >= ch) || ('A' <= ch && 'Z' >= ch) || ('0' <= ch && ch <= '9')) { f_in.get(ch); } }//------------------------------------------------------------------------------------------------------------------- else { read++; int k; f_in.seekg(pos); //f_in.get(ch); for ( k = 1; k < 4; k++) { read++; f_in.get(ch); if ( ch<'A' || (ch > 'Z'&& ch < 'a') || ch>'z' ) break; } if (k == 4) { f_in.get(ch); while (('a' <= ch && 'z' >= ch) || ('A' <= ch && 'Z' >= ch)|| ( '0' <= ch && ch <= '9')) { f_in.get(ch); read++; } pos = f_in.tellg(); f_in.seekg(pos - read); getline(f_in, str_1, ch); store_str(str_1); f_in.seekg(pos); } } } } }
这样的事情在此次的做业中还出现了不少次,这里就不在都说了。GitHub上的代码就是我和个人同伴通过相互修改后的最终结果。
一、我学到了同伴写代码时候的都看,多写的好习惯。 二、每次编写代码的时候会先写一遍伪代码。
根据以前的做业,这一次单元测试咱们仍然将**属性->连接器->输入->附加依赖项**的地址写为了Debug中的 .obj文件,可是运行包错。
改正:
由于这一次,咱们直接将类独立成了头文件,因此其实在 #include "../ConsoleApplication1/word_count.h" 这里就已经有了咱们单元测试所须要的类的定义。即咱们删除以前所修改的附加依赖项中的路径就行了。ios
测试没法经过!
缘由是咱们的路径写的是相对路径,因此没办法在当前路径下找到这个 .txt文件,最后咱们将文件拷贝到了Test项目下的路径。c++
消耗最大的函数:
git
因为这是我俩第一次用c++完成一个项目,因此咱们参考了网上的c++代码规范知否,知否github
一、结对编程让我节约了不少时间,也避免了不少没必要要的错误。“人多力量大”果真正确的。就算只有两我的,也会比一我的的写代码来的好一些。
二、编写代码上思想的一些碰撞,真的会让本身收获不少!算法