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 ...
随机推荐
- BZOJ 1640 [Usaco2007 Nov]Best Cow Line 队列变换:贪心【字典序最小】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1640 题意: 给你一个长度为n的字符串. 你可以将原串的首字母或尾字母移动到新串的末尾. ...
- 最近火狐浏览器 总是“插件 adobe flash 已崩溃”
原因和解决方案:在地址栏中输入:about:addons>在如下地方发现firefox已经在警告该插件的安全性了>选择“总不激活”
- Zookeeper用来干什么?
在Zookeeper的官网上有这么一句话:ZooKeeper is a centralized service for maintaining configuration information, n ...
- Java钉钉开发_Exception_异常总结
一.异常 1.访问ip不在白名单之中 异常信息: "errcode":60020,"errmsg":"访问ip不在白名单之中" 异常背景:若 ...
- 使用msiexec提取msi包里的文件
核心:如需把d盘下abc.msi文件解包到目录d:\abc,操作如下:打开命令提示符,输入msiexec /a "d:\abc.msi" /qb TARGETDIR="D ...
- jquery.one()
one() 方法为被选元素附加一个或多个事件处理程序,并规定当事件发生时运行的函数. 当使用 one() 方法时,每个元素只能运行一次事件处理器函数. 也就是,绑定的function,只会执行一次. ...
- Set_ML
参考资料:斯坦福(http://cs231n.github.io/linear-classify/:http://cs231n.stanford.edu/slides/2017/) Mastering ...
- BZOJ1758:[WC2010]重建计划
浅谈树分治:https://www.cnblogs.com/AKMer/p/10014803.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem. ...
- C# 序列化反序列化XML的帮助类
以下是一个包装的用于序列化反序列化XML和C# 对象的类. public class XmlSerializeHelper<T> { #region Serial ...
- zoom在清除浮动中的利用
zoom 是个困惑了好久的元素,今天对它有了个初步的认识 zoom , ie 的专属属性,在其他浏览器中不起作用,它的原本功能是设置或检测对象的缩放比例(只在ie下起作用) 比如 <div ...