第三次作业姜亦航
作业链接:https://home.cnblogs.com/u/Andrewhang/
合作伙伴作业链接:https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2/homework/2879
0.0分工合作:

0.1PSP表格
|
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
|
Planning |
计划 |
||
|
· Estimate |
· 估计这个任务需要多少时间 |
20 | 15 |
|
Development |
开发 |
||
|
· Analysis |
· 需求分析 (包括学习新技术) |
45 | 30 |
|
· Design Spec |
· 生成设计文档 |
30 | 20 |
|
· Design Review |
· 设计复审 (和同事审核设计文档) |
30 | 15 |
|
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
15 | 10 |
|
· Design |
· 具体设计 |
30 | 45 |
|
· Coding |
· 具体编码 |
240 | 560 |
|
· Code Review |
· 代码复审 |
30 | 20 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
45 | 60 |
|
Reporting |
报告 |
||
|
· Test Report |
· 测试报告 |
20 | 15 |
|
· Size Measurement |
· 计算工作量 |
10 | 10 |
|
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
15 | 15 |
|
合计 |
530 |
885
|
0.2需求分析
这次我们的任务是做一个Wordcount,我们不妨简称其为,词组数量统计,核心功能经简化有以下四点:
- 统计字符数
- 统计单词数
- 统计最多的10个单词及其词频
- 统计行数
因此,我们可以使用C#构造出四个类,分别实现不同的功能,当我们需要使用某种功能的时候,我们在主函数中调用相应的类即可。
0.3生成设计文档
简略设计图如图所示。

0.4 具体开发过程
部分主要功能代码:
字符统计
class Count
{
public static int Get(string strchar, out string result)
{
char [] s=strchar.ToCharArray();
result = "";
int count=0;
for (int i = 0; i < s.Length; i++)
{
count++;
result+=s[i].ToString();
}
return count; ;
}
这里使用到了正则表达式regex,这是这次学习的重点新技术,花费了一些时间。
单词统计
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cmdStart_Click(object sender, EventArgs e)
{
string Pattern = @"\,|\.|\ |\n|\r|\?|\;|\:|\!|\(|\)|\042|\“|\”|\-|[\u4e00-\u9fa5]|[0-9]";
string textstring = "";
int j;
Hashtable ht = new Hashtable();
Regex regex = new Regex(Pattern);
textBox2.Text = "";
try
{
StreamReader sr = new StreamReader(@textBox1.Text,System.Text.Encoding.GetEncoding("GB2312"));
textstring = sr.ReadToEnd();
sr.Close();
}
catch
{
MessageBox.Show("请把test.txt文件拷贝到C:/");
}
foreach (string word in words)
{
if (word != null && word != "")
{
if (ht.Contains(word))
{
j = Convert.ToInt32(ht[word]) + 1;
ht[word]=j;
}
else
{
ht.Add(word, 1);
}
}
}
ArrayList akeys = new ArrayList(ht.Keys);
string[] keyarray = new string[akeys.Count];
int[] valuearray = new int[akeys.Count];
int index=0;
foreach (string skey in akeys)
{
keyarray[index] = Convert.ToString(skey);
valuearray[index] = Convert.ToInt32(ht[skey]);
index++;
}
for(int a=0;a<akeys.Count;a++)
{
for (int b = a+1; b < akeys.Count; b++)
{
if (valuearray[a]>valuearray[b])
{
valuearray[a] ^= valuearray[b];
valuearray[b] ^= valuearray[a];
valuearray[a] ^= valuearray[b];
string tempstr = keyarray[a];
keyarray[a] = keyarray[b];
keyarray[b] = tempstr;
}
}
}
for (int a = 0; a < akeys.Count; a++)
{
textBox2.Text = textBox2.Text + keyarray[a] + "\t" + valuearray[a] + "\r\n";
}
}
}
0.5代码复审
复审时我们将代码共同看了几遍,无明显大的错误,但却有无数bug,在其他室友的指点下,逐渐完善直到调试通过。
0.6运行结果

0.7性能改进及测试

断点测试

0.8总结感悟
随着实验一次又一次的加大难度,我们需要自主学习的东西更多了,我们不熟悉的东西也越来越多,从开始的恐惧到现在勉强完成实验,还有一点点欣慰,这次的结对编程给我的感觉是,我渐渐感受到了软件工程的意义所在,也逐渐知道了团队合作在这项浩大的工程所体现的意义,索然我们俩还没能做到最好,有很多不完善,正是这样找到自己的缺陷所在才是我们现阶段的意义。


浙公网安备 33010602011771号