項目 | 內容 |
---|---|
做業所屬課程 | 軟件工程-羅傑 |
做業要求 | 結對項目 |
項目地址 | 最長單詞鏈 |
[項目地址](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 |