第三次作业结队
1.Fork倉庫的Github項目地址
| GIT地址 | 鏈接 |
| GIT用戶名 | ?yszmxtl |
| 結對伙伴博客地址 | 鏈接 |
| 博客地址 | ?鏈接 |
| 作業鏈接 | https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/homework/2882 |
2.PSP表格
?
| PSP2.1 | Personal Software Process Stages | 預估耗時(分鐘) | 實際耗時(分鐘) |
| Planning | 計劃 | 30 | ?60 |
| · Estimate | · 估計這個任務需要多少時間 | 600 | 972 |
| Development | 開發 | ?500 | 800 |
| · Analysis | · 需求分析 (包括學習新技術) | ?50 | ?60 |
| · Design Spec | · 生成設計文檔 | ?30 | ?30 |
| · Design Review | · 設計復審 (和同事審核設計文檔) | ?30 | ?50 |
| · Coding Standard | · 代碼規范 (為目前的開發制定合適的規范) | ?30 | ?50 |
| · Design | · 具體設計 | ?50 | ?100 |
| · Coding | · 具體編碼 | ?100 | ?500 |
| · Code Review | · 代碼復審 | 30 | ?40 |
| · Test | · 測試(自我測試,修改代碼,提交修改) | ?10 | ?30 |
| Reporting | 報告 | ?20 | ?20 |
| · Test Report | · 測試報告 | ?30 | ?30 |
| · Size Measurement | · 計算工作量 | ?10 | ?20 |
| · Postmortem & Process Improvement Plan | · 事后總結, 并提出過程改進計劃 | ?20 | ?30 |
| ? | 合計 | ?455 | ?1132 |
3.計算模塊接口的設計與實現過程
?首先將上面的要求的功能分成多個函數計算,在主函數中調用如下
static void Main(string[] args){string fileName = @"G:\input.txt";Count count1 = new Count(fileName);if (File.Exists(fileName)){count1.count_characters();//統計字符數count1.count_word();//統計單詞總數count1.count_lines();//統計有效行數count1.count_words();//統計單詞出現次數 }Console.ReadKey();}然后是分別的模塊計算對應的功能:
統計字符:
public void count_characters()//統計字符數 {FileStream file1 = new FileStream(fileName1, FileMode.Open, FileAccess.Read);//打開的文件int count;count = 0;byte[] buf = new byte[file1.Length];//緩存區接受文件夾中的內容file1.Read(buf, 0, buf.Length);for (int a = 0; a < buf.Length; a++)//利用循環判斷是否為字符 {if ((int)buf[a] <= 127)count++;}//File.AppendAllText(@"G:\output.txt", "characters:");//強制輸入某段數據到指定文件夾string avaible1 = "character: ";string avaible2;avaible2 = Convert.ToString(count);Console.WriteLine(avaible1 + avaible2);avaible1 = avaible1 + avaible2;StreamWriter file2 = new StreamWriter(fileName2, true);//寫入該文件夾中,true表示追加到問價下一行 file2.WriteLine(avaible1);file2.Flush();file1.Close();file2.Close();}?統計單詞總數:
public void count_word()//統計單詞總數 {Dictionary<string, int> dictionary_1;List<string> listLines = new List<string>();StreamReader reader = new StreamReader(@"G:\input.txt");string line = reader.ReadLine();while (line != "" && line != null){listLines.Add(line);line = reader.ReadLine();}string str1;str1 = "";for (int i = 0; i < listLines.Count; i++){str1 = str1 + listLines[i];}dictionary_1 = new Dictionary<string, int>();string[] words = Regex.Split(str1, @"\W+");int counts;counts = 0;foreach (string word in words){if (dictionary_1.ContainsKey(word)){dictionary_1[word]++;}else{dictionary_1[word] = 1;}}foreach (KeyValuePair<string, int> avaible_1 in dictionary_1){if(avaible_1.Key.Length>=4){string word = avaible_1.Key;int count = avaible_1.Value;counts = counts + count;} //Console.WriteLine("{0}:{1}", word, count); }string avaible_2, avaible_3;avaible_2 = "words: ";Console.WriteLine(avaible_2 + counts);avaible_3 = Convert.ToString(counts);avaible_2 = avaible_2 + avaible_3;StreamWriter file2 = new StreamWriter(fileName2, true);file2.WriteLine(avaible_2);file2.Flush();file2.Close();}?統計有效行數:
public void count_lines()//統計有效行數 {int count;count = 0;string[] str = File.ReadAllLines(fileName1, System.Text.Encoding.Default);count = str.Length;string avaible_1, avaible_2;avaible_1 = "lines: "; Console.WriteLine(avaible_1+count);avaible_2 = Convert.ToString(count);avaible_1 = avaible_1 + avaible_2;StreamWriter file = new StreamWriter(fileName2, true);file.WriteLine(avaible_1);file.Flush();file.Close();}?統計單詞數:
public void count_words()//統計單詞出現次數 {Dictionary<string, int> dictory_1 = new Dictionary<string, int>();dictory_1 = sortdictionary_desc(dictory_1);Dictionary<string, int> dictory_2 = new Dictionary<string, int>();int avaible_2;avaible_2 = 0;foreach(KeyValuePair<string, int> sw in dictory_1){avaible_2++;dictory_2.Add(sw.Key,sw.Value);if (avaible_2 == 10)break;}List<KeyValuePair<string, int>> myList = new List<KeyValuePair<string, int>>(dictory_2);myList.Sort(delegate (KeyValuePair<string, int> s1, KeyValuePair<string, int> s2){return s1.Key.CompareTo(s2.Key);});dictory_2.Clear();foreach (KeyValuePair<string, int> pair in myList){dictory_2.Add(pair.Key, pair.Value);}foreach (KeyValuePair<string, int> avaible_1 in dictory_2){string avaible_3 ="<"+ avaible_1.Key+">";int avaible_4 = avaible_1.Value;Console.WriteLine("{0}:{1}", avaible_3, avaible_4);string sr = Convert.ToString(avaible_4);avaible_3 = avaible_3 + ": ";avaible_3 = avaible_3 + sr;StreamWriter stream = new StreamWriter(fileName2, true);stream.WriteLine(avaible_3);stream.Flush();stream.Close();} }public Dictionary<string,int> sortdictionary_desc(Dictionary<string,int> dic)//對字典中的數據按照value排序 {Dictionary<string, int> dictionary_1;List<string> listLines = new List<string>();StreamReader reader = new StreamReader(@"G:\input.txt");string line = reader.ReadLine();while (line != "" && line != null){listLines.Add(line);line = reader.ReadLine();}string str1;str1 = "";for (int i = 0; i < listLines.Count; i++){str1 = str1 + listLines[i];}dictionary_1 = new Dictionary<string, int>();string[] words = Regex.Split(str1, @"\W+");foreach (string word in words){if (dictionary_1.ContainsKey(word)){dictionary_1[word]++;}else{dictionary_1[word] = 1;}}List<KeyValuePair<string, int>> myList = new List<KeyValuePair<string, int>>(dictionary_1);myList.Sort(delegate (KeyValuePair<string, int> s1, KeyValuePair<string, int> s2){return s2.Value.CompareTo(s1.Value);});dictionary_1.Clear();int n = 0;foreach (KeyValuePair<string, int> pair in myList){if(pair.Key.Length>=4){n++;dictionary_1.Add(pair.Key, pair.Value);}if (n == 10)break;}return dictionary_1;}?運行效果如下:
?
?
?
?
?
4.代碼復審過程。
敲好代碼后,發現不符合題的規則,就是那個單詞判斷那,我直接運用網上說的正則表達式算出來,發現有的單詞是一個字母,然后就改寫了代碼。
?
5.計算模塊接口部分的性能改進、效能分析。
?
?
其中有一些寫了沒用過的變量,進行刪除,如下:
?將這個定義刪掉之類的
?可以將上面的改成如下:
?就少定義了一個變量,然后其它函數也一樣,因為有好多類似的
?
6.計算模塊部分單元測試展示
?
7.描述結對的過程
我敲代碼,他在旁邊審查合理性,并提供思維和資料。
8.代碼規劃
除了一次型變量用單個字母定義外,其它的都用單詞定義,空格這些和縮進直接打了確認建不管。
?
轉載于:https://www.cnblogs.com/pingecy/p/10642175.html
總結
- 上一篇: 初识Anrdiod SDK
- 下一篇: NDK学习笔记-JNI的引用