项目 | 内容 |
---|---|
做业所属课程 | 软件工程-罗杰 |
做业要求 | 结对项目 |
项目地址 | 最长单词链 |
[项目地址](https://github.com/Androider666/Wordlist)git
PSP2.1 | Person Software Process Stages | 预计耗时(min) | 实际耗时(min) |
---|---|---|---|
Planning | 计划 | 1900 | |
· Estimate | · 估计这个任务须要多少时间 | 1900 | |
Development | 开发 | 1600 | |
· Analysis | · 需求分析 (包括学习新技术) | 300 | |
· Design Spec | · 生成设计文档 | 100 | |
· Design Review | · 设计复审 (和同事审核设计文档) | 30 | |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 30 | |
· Design | · 具体设计 | 180 | |
· Coding | · 具体编码 | 600 | |
· Code Review | · 代码复审 | 180 | |
· Test | · 测试(自我测试,修改代码,提交修改) | 180 | |
Reporting | 报告 | 300 | |
· Test Report | · 测试报告 | 180 | |
· Size Measurement | · 计算工做量 | 60 | |
· Postmortem & Process Improvement Plan | · 过后总结, 并提出过程改进计划 | 60 | |
合计 | 1900 |
Information Hiding:信息隐藏,防止他人篡改数据
Interface Design:接口设计,提供必定的接口使系统能与外界进行交互,同时使得数据安全可控
Loose Coupling:松耦合,下降函数之间的依赖程度,避免牵一发而动全身的修改github
计算模块一个Core类,提供四个接口方法
1.int static gen_chain_word(char* words[], int len, char* result[], char head, char tail,2. bool enable_loop);
2.int static gen_chain_char(char* words[], int len, char* result[], char head, char tail, bool enable_loop);
3.bool static has_circle(char words[], int len);
4.int static readfile(char path, char words[]);
第一和第二个接口寻找符合要求的最长路径,第三个接口判断字符串数组是否有环,有环返回true,无环返回false,第四个接口读取文件并返回字符串数组。
以上四个接口调用了3个私有函数:
1.int LONG(WORD wod, int len, char *result[], int H, int T, char _h, char _t, int mark);
2.int nocircle(WORD words[], int len);
3.int in_array(char arr, int len, char cc);
typedef struct struct1 {
char h;
char t;
char word;
}Word, *WORD;
LONG函数第一个参数是字符串数组转化为自定义结构体数组,第二个参数是结构体数组大小,H为1,表明有-h参数,为0,表明无-h参数,T参数同理;_h表明首字母,_t表明尾字母,且仅仅当其为'a'-'z'时才起做用,不然报错,mark为0标记求最长单词数,为1标记求最多字符数。
nocircle传入字符数组,及长度,如有环返回0,不然返回1
in_array寻找字符cc在字符数组arr中的下表,若找到,返回下标,不然返回-1;算法
int len1 = 10, len2 = 11; char *list1[10] = {"app","pdfcde","hefarry","yakorm","morning","ed","dail","left","pd","dot" }; char *list2[11] = { "app","pdfcde","pd","die","early","ear","yet","tail","rabbittall","tab","leaf" }; TEST_METHOD(TestMethod1) { // TODO: 在此输入测试代码 int ans_len = 5; char *ans[5] = { "app","pdfcde","ed","dail","left" }; char *result[5]; int len = 0; len = Core::gen_chain_word(list1, len1, result, '\0', '\0', false); Assert::AreEqual(len, ans_len); Assert::AreEqual(strcmp(longchar(result, len), longchar(ans, ans_len)), 0); Assert::IsFalse(Core::has_circle(list1,len1)); } TEST_METHOD(TestMethod6) { int ans_len = 3; char *ans[3] = { "hefarry","yakorm","morning" }; char *result[3]; int len = 0; len = Core::gen_chain_char(list1, len1, result, '\0', '\0', false); Assert::AreEqual(len, ans_len); Assert::AreEqual(strcmp(longchar(result, len), longchar(ans, ans_len)), 0); Assert::IsFalse(Core::has_circle(list1, len1)); }
测试的思路是在测试模块中list里保存全部的单词,用result存输出的结果,调用core计算模块中gen_chain_word和gen_chain_char接口,将返回值存入len中,最后把返回到result中的结果和预期的ans进行比对。针对每个接口,经过-h、-t、-r参数的组合来编造相应的测试用例。编程
咱们分析到的异常有单词的格式错误,好比单词内出现非法字符;当没有-r参数时,单词表内存在单词环等等,如下为错误处理
void Error(int n) {
cout << "Error: ";
switch (n) {
case 1: cout << "wrong format after -h!"; break;
case 2: cout << "wrong format after -t!"; break;
case 3: cout << "wrong format in argvs!"; break;
case 4: cout << "file doesn't exsits!"; break;
case 5: cout << "error when read file!"; break;
case 6: cout << "There exists circle(s),check words again!"; break;
case 7: cout << "error when write data!"; break;
case 8: cout << "number of words larger than 10000!"; break;
case 9: cout << "number of words larger than 100!"; break;
default:break;
}
exit(0);
}数组
1 wrong format after -h!
2 wrong format after -t!
3 wrong format in argvs!
4 file doesn't exsits!
5 error when read file!
6 There exists circle(s),check words again!
7 error when write data!
8 number of words larger than 10000!
9 number of words larger than 100!安全
用户指令经过main函数的参数int main(int argc,char **argvs)中的argvs字符串数组进行获取,并对其进行解析,包括错误处理。即用户指令经过命令行获取。
app
根据命令行地址参数,读取文件信息,转化为字符串数组。根据字符串数组构造出自定一的结构体数组。首先判断字符串nocicle()函数判断是否能成环,若能成环且命令行不含-r参数,则报错,不然,进入LONG()函数寻找符合要求的最长单词链。
nocicle函数的具体实现思想:先将首尾字母相同的字符串剔除,对剩下的字符串数组进行判断,记录下26个字母做为剩下字符串数组的首尾字母出现的次数(并去除从未在首尾部出现过的字母),若某一字母在剩下的字符串的首部出现次数为0或者尾部出现次数为0,则将该字母来源的字符串从字符串数组中剔除,将该字母从字母数组中剔除,重复操做,知道字符串数组无变化;根据这个方法,能够想象每次剔除链端字符串及其离环或者链中心最远一端的字母,知道最后无链端存在,若存在环,则最后字符串数组大小大于0,不然为0。
LONG函数具体实现思想:26 * 26 * n的数组存字符串(n表示有多少个字符串对应首字母相同,尾字母相同),[x][y][z]为下标,x为首部字母减去'a',y为尾字母减去‘a’,z根据字符串长度由大到小排序,从横纵坐标最大的[x][y]开始访问,每次访问[x][y][top],top从小到大,访问一次[x][y],top就+1(注意每个[x][y]字符串数组都有一个top值,且不断变化,和对应left[x][y]之和为一个定值),left[x][y]-1,不然top-1,left[x][y]+1,其中left[..][..]记录对应下标还能访问的剩下字符串个数,保证每次访问剩下的首尾字母相同的字符串时访问长度最长的那个;而后访问[y][..]那一行,从右往左,访问left[..][..]大于0的top位字符串,依次下去直到left[y][..]都为0,一个长链结束。接着回退到父节点的[x][<y],访问最近的left[x][<y]大于0的top位字符串,若left[x][<y]都等于0,则再次回退到祖父节点的left[<.][<.],依次下去访问,直到left[.][<.]不为0,继续访问其后继节点,造成新的长链。ide
int static readfile(char path, char words[]);readfile模块根据用户指令提供的文件路径返回字符串数组及字符串个数;
用户指令中若存在-h,或-t参数,则head,tail分别其后所跟的字符,不然head,tail为'\0'; 若存在-r,enable_loop为true,不然为false;若不存在-r参数,且存在单词环,则报错,不然若单词个数知足要求,则调用相应计算模块;
具体调用: 若存在-w参数,调用int static gen_chain_word(char* words[], int len, char* result[], char head, char tail,2. bool enable_loop);若存在-c参数,调用int static gen_chain_char(char* words[], int len, char* result[], char head, char tail, bool enable_loop);函数
算法以及代码由我负责,测试数据由队友负责
oop
结对编程优势:1.交流进步2.认识本身不足3.向他人学习
缺点:1.容易产生分歧2.很难独立思考3.效率低
本人优缺点: 本人偏向于工程写代码,独立思考能力强,有毅力,缺点: 不太爱交流。
队友优缺点: 理解能力强,擅长写测试数据,细致认真,缺点: 有点拖延症。
PSP2.1 | Person Software Process Stages | 预计耗时(min) | 实际耗时(min) |
---|---|---|---|
Planning | 计划 | 1900 | 2070 |
· Estimate | · 估计这个任务须要多少时间 | 1900 | 2070 |
Development | 开发 | 1600 | 1920 |
· Analysis | · 需求分析 (包括学习新技术) | 300 | 420 |
· Design Spec | · 生成设计文档 | 100 | 100 |
· Design Review | · 设计复审 (和同事审核设计文档) | 30 | 30 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 30 | 30 |
· Design | · 具体设计 | 180 | 200 |
· Coding | · 具体编码 | 600 | 720 |
· Code Review | · 代码复审 | 180 | 180 |
· Test | · 测试(自我测试,修改代码,提交修改) | 180 | 240 |
Reporting | 报告 | 300 | 150 |
· Test Report | · 测试报告 | 180 | 60 |
· Size Measurement | · 计算工做量 | 60 | 60 |
· Postmortem & Process Improvement Plan | · 过后总结, 并提出过程改进计划 | 60 | 30 |
合计 | 1900 | 2070 |