WC-第二次作业
WordCount 第二次作业
码云地址:https://gitee.com/lgcj1218/WordCount/tree/master
一.解题思路
本次作业采用的c#语言 按功能分为了三个类 ,计算字符数,计算单词数,计算行数。然后在主程序中new三个类,当需要进行着三个功能时就调用其中的函数。
二.代码说明
1.主程序(包含输出文件的方法)
static void Main(string[] args)
{
string cmd = "";
while (cmd != "leave")
{
int i;
int charCount, wordCount, lineCount;
string testFile;
string outFile;
Console.Write("wc.exe ");
cmd = Console.ReadLine();
string[] arrMessSplit = cmd.Split(' ');
List<string> arrParameter = new List<string>();
for (i = ; i < arrMessSplit.Length; i++)
{
arrParameter.Add(arrMessSplit[i]);
}
bool isOut = false;
for (i = ; i < arrMessSplit.Length - ; i++)
{ if (arrParameter[i] == "-o")
{
isOut = true;
}
} CharCount cc = new CharCount();
WordCount wc = new WordCount();
LineCount lc = new LineCount();
if (isOut)
{
testFile = arrParameter[arrParameter.Count - ];
for (i = ; i < arrMessSplit.Length - ; i++)
{
if (arrParameter[i] == "-c")
{
cc.CC(testFile);
}
if (arrParameter[i] == "-w")
{
wc.WC(testFile);
}
if (arrParameter[i] == "-l")
{
lc.LC(testFile);
}
}
outFile = arrParameter[arrParameter.Count - ];
FileStream fs = new FileStream(outFile, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write("{0},charCount:{1}\r\n", testFile, cc.charCount);
sw.Write("{0},wordCount:{1}\r\n", testFile, wc.wordCount);
sw.Write("{0},lineCount:{1}\r\n", testFile, lc.lineCount);
sw.Flush();
sw.Close();
fs.Close();
Console.WriteLine("WriteToFile:{0}", outFile);
}
else
{
testFile = arrParameter[arrParameter.Count - ];
for (i = ; i < arrMessSplit.Length - ; i++)
{
if (arrParameter[i] == "-c")
{
cc.CC(testFile);
} if (arrParameter[i] == "-w")
{
wc.WC(testFile);
} if (arrParameter[i] == "-l")
{
lc.LC(testFile);
}
}
}
Console.ReadLine();
}
}
}
}
program
2.计算字符数的类
class CharCount
{ public string testFile;
public int charCount = ;
public void CC(string testFile)
{ int nChar;
char[] symbol = { ' ', ',' };
FileStream file = new FileStream(testFile, FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(file);
while ((nChar = sr.Read()) != -)
{
charCount++;
}
Console.WriteLine("{0},charCount:{1}", testFile, charCount);
}
}
charcount
3.计算单词数的类
class WordCount
{
public string testFile;
public int wordCount=;
public void WC(string testFile)
{ int nChar;
char[] divide = { ' ', ',' };
FileStream file = new FileStream(testFile, FileMode.Open,FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(file);
while ((nChar = sr.Read()) != -)
{
foreach (char c in divide)
{
if (nChar == (int)c)
{
wordCount++;
}
}
}
wordCount++;
Console.WriteLine("{0},wordCount:{1}", testFile, wordCount);
}
}
wordcount
4.计算行数的类
class LineCount
{
public string testFile;
public int lineCount = ;
public void LC(string testFile)
{ int nChar;
char[] divide = { ' ', ',' };
FileStream file = new FileStream(testFile, FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(file);
while ((nChar = sr.Read()) != -)
{
if (nChar == '\n')
{
lineCount++;
}
}
lineCount++;
Console.WriteLine("{0},lineCount:{1}", testFile, lineCount);
}
}
linecount
三.测试设计过程
1.测试写入文件

2.测试计算字符,单词和行数的功能

WC-第二次作业的更多相关文章
- 软件工程(GZSD2015)第二次作业小结
第二次作业,从4月7号开始,陆续开始提交作业.根据同学们提交的作业报告,相比第一次作业,已经有了巨大改变,大家开始有了完整的实践,对那些抽象的名词也开始有了直观的感受,这很好.然后有一些普遍存在的问题 ...
- 软件工程(GZSD2015) 第二次作业小结
第二次作业,从4月7号开始,陆续开始提交作业.根据同学们提交的作业报告,相比第一次作业,已经有了巨大改变,大家开始有了完整的实践,对那些抽象的名词也开始有了直观的感受,这很好.然后有一些普遍存在的问题 ...
- 耿丹CS16-2班第二次作业汇总
-- Deadline: 2016-09-28 12:00 -- 作业内容:http://www.cnblogs.com/huangjunlian/p/5891726.html -- 第二次作业总结: ...
- JAVA第二次作业展示与学习心得
JAVA第二次作业展示与学习心得 在这一次作业中,我学习了复选框,密码框两种新的组件,并通过一个邮箱登录界面将两种组件运用了起来.具体的使用方法和其他得组件并没有什么大的不同. 另外我通过查阅资料使用 ...
- 20169212《Linux内核原理与分析》第二周作业
<Linux内核原理与分析>第二周作业 这一周学习了MOOCLinux内核分析的第一讲,计算机是如何工作的?由于本科对相关知识的不熟悉,所以感觉有的知识理解起来了有一定的难度,不过多查查资 ...
- 软件工程(QLGY2015)第二次作业点评(随机挑选20组点评)
相关博文目录: 第一次作业点评 第二次作业点评 第三次作业点评 说明:随机挑选20组点评,大家可以看看blog名字,github项目名字,看看那种是更好的,可以学习,每个小组都会反应出一些问题,希望能 ...
- 程序设计第二次作业<1>
面向对象程序设计第二次作业<1> Github 链接:https://github.com/Wasdns/object-oriented 题目: <1>第一次尝试 我立马认识到 ...
- homework-02,第二次作业——寻找矩阵最大子序列和
经过漫漫漫~~~~~~~~~~~~~~长的编译和调试,第二次作业终于告一段落了 先放出源码,思路后面慢慢道来 #include<stdio.h> #include<stdlib.h& ...
- 20169210《Linux内核原理与分析》第二周作业
<Linux内核原理与分析>第二周作业 本周作业分为两部分:第一部分为观看学习视频并完成实验楼实验一:第二部分为看<Linux内核设计与实现>1.2.18章并安装配置内核. 第 ...
- SQL 第二章 作业
/*第二章 作业*/ create table S ( sno char(2) NOT NULL UNIQUE, sname char(3), city char(2) ); alter table ...
随机推荐
- 9.2 NOIP提高组试题精解(2)
9-18 fruit.c #include <stdio.h> #define MAXN 10000 int Queue1[MAXN], Queue2[MAXN]; void Insert ...
- CentOS 7 设置自定义开机启动,添加自定义系统服务
详细文档,http://www.linuxidc.com/Linux/2015-04/115937.htm 摘自: http://www.centoscn.com/CentOS/config/2015 ...
- 9--RESTful支持
1.对url进行规范,写RESTful格式的url 非REST的url:http://...../queryItems.action?id=001&type=T01 REST的url风格:ht ...
- 带动画效果的jQuery手风琴
带动画效果的jQuery特效手风琴是一款带动画效果的手风琴作品,非常实用,可以用在新闻列表.FAQ等模块,默认的是打开第一个选项,查看其它的时候直接点击加号按钮就展开. 源码地址:http://www ...
- layer 插件 在子页面关闭自身的方法
先取到该子页面在父级页面中的name 值 var index= parent.layer.getFrameIndex(Window.name); 然后用该方法关闭 parent.layer.clos ...
- 岭回归与Lasso回归
线性回归的一般形式 过拟合问题及其解决方法 问题:以下面一张图片展示过拟合问题 解决方法:(1):丢弃一些对我们最终预测结果影响不大的特征,具体哪些特征需要丢弃可以通过PCA算法来实现:(2):使用正 ...
- Anomaly Detection for Time Series Data with Deep Learning——本质分类正常和异常的行为,对于检测异常行为,采用预测正常行为方式来做
A sample network anomaly detection project Suppose we wanted to detect network anomalies with the un ...
- ES忽略TF-IDF评分——使用constant_score
Ignoring TF/IDF Sometimes we just don’t care about TF/IDF. All we want to know is that a certain wor ...
- python做图笔记
1. 工具选择 了解了基本python,rodeo,anaconda套件这三种工具. (1)基本python,下载安装python的最新版(目前是python3.7).注意要使用安装版.安装好后,一般 ...
- 勤于思考:Objective-C特性的扩展
赋值 assign:直接赋值.默认 @interface Car : NSObject { NSString *_name; } @property (assign,nonatomic) NSStri ...