Mooonnnn

导航

第三次作业

一、地址

        GitHub地址:https://github.com/leerijin/WordCount

        结对伙伴地址:https://www.cnblogs.com/riverspring/

二、结对过程

        和结对伙伴首先一起阅读了本次的作业要求,然后共同制定了代码规范,接着简单讨论了一下如何实现功能,并进行了分工。

三、PSP表格

 

PSP2.1

Personal Software Process Stages

预估耗时(分钟)

实际耗时(分钟)

Planning

计划

 25

 20

· Estimate

· 估计这个任务需要多少时间

 25

 20

Development

开发

 1340

 1290

· Analysis

· 需求分析 (包括学习新技术)

 60

 80

· Design Spec

· 生成设计文档

 20

 20

· Design Review

· 设计复审 (和同事审核设计文档)

 20

 25

· Coding Standard

· 代码规范 (为目前的开发制定合适的规范)

 30

 25

· Design

· 具体设计

 60

 70

· Coding

· 具体编码

1000

 900

· Code Review

· 代码复审

 30

 20

· Test

· 测试(自我测试,修改代码,提交修改)

 120

 150

Reporting

报告

 60

 85

· Test Report

· 测试报告

 30

 40

· Size Measurement

· 计算工作量

 10

 15

· Postmortem & Process Improvement Plan

· 事后总结, 并提出过程改进计划

 20

 30

 

合计

 1425

 1395

 四、代码规范

        1、函数名使用相应的英文单词或中文缩写;
        2、代码较复杂的地方添加注释;
        3、功能尽量在其他函数中实现;
        4、大括号的上半部分和下半部分对齐,代码格式清晰。

五、解题思路

        首先在主函数中实现文件的读取和结果输出,用字符串接收读入的文件内容,统计出字符数;之后将单词传给新的字符串,再统计词频。

六、设计过程实现

七、代码复审

        与结对伙伴各自完成分工的代码后,我们互相看了对方所负责的代码部分,并将它们结合到一起。在结合的过程中发现双方的代码有连接不上或者是重复的地方,就此做了一些改正。

八、代码说明

         统计单词个数

 1 public static int GetWnum(string str,ref string word)
 2         {
 3             int k = 0;
 4             string temp1 = "";
 5             for (int i = 0; i < str.Length; i++)
 6             {
 7                 if (char.IsLetter(str[i]) || char.IsDigit(str[i])) //判断是不是数字或者字母
 8                 {
 9                     temp1 += str[i];
10                 }
11                 else
12                 {
13                     temp1 += " ";
14                 }
15             }
16 
17             string[] arr = temp1.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); //去除字符数组中所有空格
18             string arr1 = string.Join(" ", arr);
19             string[] temp2 = arr1.Split(' ');
20             int j = 0, flag = 1;
21             for (int i = 0; i < temp2.Length; i++)
22             {
23                 if (temp2[i].Length < 4)
24                 {
25                     continue;
26                 }
27                 else
28                 {
29                     for (j = 0; j < 4; j++) //判断前四个是否为字母
30                     {
31                         flag = 1;
32                         if (char.IsDigit(temp2[i][j]))
33                         {
34                             flag = 0;
35                         }
36 
37                     }
38 
39                     if (flag == 1)
40                     {
41                         k++;
42                         word += temp2[i] + " ";
43                     }
44                 }
45             }
46 
47             return k;
48         }

        统计词频

 1  public static string GetStr(string str1)
 2         {
 3             if (str1=="")
 4             {
 5                 return "";
 6             }
 7             int j = 0;
 8             str1 = str1.Trim();
 9             string[] str = str1.Split(' ');
10             List<System.String> strList=new List<System.String>(str);
11             strList.Sort();
12             str = strList.ToArray();      //将LIST转换成string[]
13             var temp1 = str.GroupBy(i => i).ToList();
14             string temp = "";
15             //temp1.ForEach(i =>
16             //{
17             //    string wordi = i.Key;
18             //    int timei = i.Count();
19             //    temp += wordi + ":" + timei + "\r\n";
20             //});
21             foreach (var i in temp1)
22             {
23                 string wordi = i.Key;
24                 int timei = i.Count();
25                 temp += wordi + ":" + timei + "\r\n";
26                 j++;
27                 if (j == 10)
28                 {
29                     break;
30                 }
31             }
32             return temp.ToLower();
33         }

 

九、运行结果

 

十、单元测试

 

十一、效能分析

 

十二、总结

        本次作业一开始进行得很顺利,但完成基本功能后,便遇到了许多问题:封装过程中有些类库无法引用、写新增功能时没有搞清楚要求……遇到问题之后本人与结对伙伴一起或上网搜索,或询问身边专业能力较好的同学,基本解决了这些问题,但也浪费了一定的时间。

        这也是本人第一次体验合作完成代码,固然体验到了合作的好处:遇到问题两个人可以一起解决、遇到瓶颈时可以有两种思维想法。但同时也由于经验不足以及默契度不够,而浪费了许多时间在双方的配合上。不过总的来说,是一次非常棒的经历,也相信通过这次的作业,大家都能在与他人交流合作方面有所提高。

posted on 2019-04-05 22:49  Mooonnnn  阅读(187)  评论(2编辑  收藏  举报