個人項目地址:https://github.com/JPL1988/WordCount.githtml
結對夥伴地址:https://www.cnblogs.com/l123456l/p/10628055.htmlgit
此次做業是和老龍一塊兒合做的,他對於項目的總體佈局和細節提出了很好的建議,雖然項目比較簡陋,可是都付出了很大的努力。github
PSP2.1編程 |
Personal Software Process Stages佈局 |
預估耗時(分鐘)性能 |
實際耗時(分鐘)學習 |
Planning測試 |
計劃編碼 |
10 | 10 |
· Estimatespa |
· 估計這個任務須要多少時間 |
||
Development |
開發 |
150 | 180 |
· Analysis |
· 需求分析 (包括學習新技術) |
60 | 80 |
· Design Spec |
· 生成設計文檔 |
40 | 30 |
· Design Review |
· 設計複審 (和同事審覈設計文檔) |
30 | 15 |
· Coding Standard |
· 代碼規範 (爲目前的開發制定合適的規範) |
30 | 20 |
· Design |
· 具體設計 |
30 | 20 |
· Coding |
· 具體編碼 |
40 | 35 |
· Code Review |
· 代碼複審 |
30 | 30 |
· Test |
· 測試(自我測試,修改代碼,提交修改) |
30 | 20 |
Reporting |
報告 |
20 | 20 |
· Test Report |
· 測試報告 |
20 | 15 |
· Size Measurement |
· 計算工做量 |
30 | 20 |
· Postmortem & Process Improvement Plan |
· 過後總結, 並提出過程改進計劃 |
20 | 15 |
合計 |
540 | 510 |
1,經過命令行啓動程序,識別文件
2,把文件所有讀取進一個字符串,經過字符串長度求文件字符數
3,遍歷字符串,同時統計單詞總數
4,將字符串分割爲單個字符串,用dictionary儲存字符串和字符串出現次數
5,遍歷dictionary一次找到一個出現頻率最高的字符串,而後找到10個字符串
6,經過比較字符大小進行字典排序
countword類: OutPut方法:調用其它方法並實現輸出
CountLines方法:統計總行數
SplitString方法:將每一個單詞分割出來
ComputeWords方法:全部單詞的個數
CountTimes方法:某個單詞出現的次數
Program類:Main方法:傳入文本路徑並執行程序
https://blog.csdn.net/qq_31606375/article/details/77783328
分離出每一個單詞
public void SplitString(string FileTxt) { int i = 0; int Chars = 0; int count = 0; string temp = null; while (i < FileTxt.Length) { if (FileTxt[i] == ' ' || (FileTxt[i] > '0' && FileTxt[i] < '9')) { while ((FileTxt[i] > '0' && FileTxt[i] < '9')) { i++; Chars++; } if (Chars != 0) { temp = FileTxt.Substring(i - Chars, Chars).ToLower(); if (dictionary.ContainsKey(temp)) { dictionary.TryGetValue(temp, out count); dictionary.Remove(temp); dictionary.Add(temp, ++count); } else { if (temp.Length >= 4) dictionary.Add(temp, 1); } if (FileTxt[i] == ' ') Chars = 0; else Chars = 1; } } else { Chars++; } i++; } }
統計行數
public int CountLines(String filepath) { Stopwatch sw = new Stopwatch(); int lines = 0; //按行讀取 sw.Restart(); using (var sr = new StreamReader(filepath)) { string ls = ""; //循環讀取直到最後一行 while ((ls = sr.ReadLine()) != null) { //如果換行符行數不變 if (ls.Length != 0) lines++; } } sw.Stop(); return lines; }
統計字符總數
public int ComputeWords(string FileTxt) { int count = 0; int result = 0; int i = 0; //遍歷整個文件字符串 while (i<FileTxt.Length) { if(FileTxt[i] == '\n') { FileTxt.Remove(i,1); } //若不是文件分隔符,則單詞長度加1,不然判斷前字符串是不是單詞 if(FileTxt[i]==' '||(FileTxt[i]>'0'&&FileTxt[i]<'9')) { while ((FileTxt[i] > '0' && FileTxt[i] < '9')) { i++; count++; } if (count >= 4) { result++; } if (FileTxt[i] == ' ') count = 0; else count = 1; } else { count++; } i++; } return result; }
經過此次結對編程學會了討論分析並改進程序,感覺到了合做的好處。