第四次作业-结对编程
| 项目地址 | https://github.com/aSmallAlan/WordCount |
|---|---|
| 结对伙伴 | 没有结对伙伴,由于是大四的,没有认识的小伙伴 |
1.PSP表格
|
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
|
Planning |
计划 |
30 |
20 |
|
· Estimate |
· 估计这个任务需要多少时间 |
120 |
240 |
|
Development |
开发 |
60 |
200 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
30 |
20 |
|
· Design Spec |
· 生成设计文档 |
20 |
20 |
|
· Design Review |
· 设计复审 (和同事审核设计文档) |
20 |
10 |
|
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
10 |
20 |
|
· Design |
· 具体设计 |
30 |
20 |
|
· Coding |
· 具体编码 |
120 |
240 |
|
· Code Review |
· 代码复审 |
20 |
10 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
20 |
20 |
|
Reporting |
报告 |
10 |
20 |
|
· Test Report |
· 测试报告 |
10 |
10 |
|
· Size Measurement |
· 计算工作量 |
30 |
40 |
|
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
10 |
30 |
|
|
合计 |
570 |
650 |
2.模块设计
1.定义全局数组,用来储存将会写入文件的信息
public static string[] Information = {"","",""};//定义写入文件的3种信息
2.统计字符数的方法
public int CharCount(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);//打开文件
string wordsNumber = Convert.ToString(fs.Length);//读出文件中的长度信息,即字符数
fs.Close();
Console.Write("字符统计成功 ");
return int.Parse(wordsNumber);//返回读出的字符数
}
3.统计单词数的方法
public int WordCount(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);//打开文件
StreamReader sr = new StreamReader(fs, Encoding.Default);//用特定方式读取文件中信息
string s = sr.ReadToEnd();//读出所有信息
fs.Close();
sr.Close();
char[] c = { ' ', ',', ','};//定义跳过的字符类型
string[] words = s.Split(c, StringSplitOptions.RemoveEmptyEntries);//将读出的信息按跳过的字符类型,分割成字符串
Console.Write("单词统计成功 ");
return words.Length;//返回字符串的个数,即单词数
}
4.统计行数的方法
//统计行数的方法
public int RowsCount(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);//打开文件
StreamReader sr = new StreamReader(fs, Encoding.Default);//用特定方式读取文件中信息
string s = sr.ReadToEnd();//读出所有信息
fs.Close();
sr.Close();
char[] c = { '\n' };//定义跳过的字符类型,换行符
string[] words = s.Split(c, StringSplitOptions.RemoveEmptyEntries);//将读出的信息按跳过的字符类型,分割成字符串
Console.Write("行数统计成功 ");
return words.Length;//返回字符串的个数,即行数
}
5.写入文件的方法
public void WriteIn()
{
FileStream fs = new FileStream("F:\\result.txt", FileMode.Create);//定义文件操作类型,实例化
StreamWriter sw = new StreamWriter(fs);//用特定方式写入信息,实例化
for (int i=0;i<3;i++)
{
sw.Write(Information[i]);//写入第i种信息
sw.Write("\r\n");//换行
}
sw.Flush();
sw.Close();
fs.Close();
Console.Write("文件写入成功 ");
}
字符数统计,单词数统计,行数统计,文件写入这4个功能分别写一个方法,定义在一个类中,在主函数里面调用这几个方法
3.测试



浙公网安备 33010602011771号