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 ...
随机推荐
- uploadify 报错 超过了最大请求长度
今天系统遇到了一个问题,上传4m以上的文件,uploadify就会报错:超过了最大请求长度. 开始我以为是设置的大小,可是后来我看了uploadify的fileSizeLimit=1024*10,也就 ...
- python无法安装cv2的解决办法
问题:在windows命令窗口输入pip install cv2后出现:Could not find a version that satisfies the requirement cv2... 解 ...
- 最近采集写的一个超简单实用的HTML解析类
1. [文件] HtmlDom.php <?php$oldSetting = libxml_use_internal_errors( true ); libxml_clear_errors(); ...
- Android 7.1 GUI系统-窗口管理WMS-Surface管理(四)
Surface的管理 Surface是窗口能真正显示到物理屏幕上的基础,由surfaceflinger管理,可以通过WindowStateAnimator.java中的变量mDrawState来查看每 ...
- 岭回归与Lasso回归
线性回归的一般形式 过拟合问题及其解决方法 问题:以下面一张图片展示过拟合问题 解决方法:(1):丢弃一些对我们最终预测结果影响不大的特征,具体哪些特征需要丢弃可以通过PCA算法来实现:(2):使用正 ...
- selenium 经常用到的API
一.webdriver 属性及方法: 1.获取当前页面的 url driver.current_url 2 .获取窗口相关信息 get_window_position() 返回窗口x,y坐标 get_ ...
- 小程序js页面设置上导航颜色
//导航条颜色更改 wx.setNavigationBarColor({ frontColor: '#ffffff', // 必写项 backgroundColor: '#008de6', // 必写 ...
- ACM学习历程——HDU1331 Function Run Fun(锻炼多维dp的打表)
Description We all love recursion! Don't we? Consider a three-parameter recursive function w( ...
- Html5 canvas 元素
canvas 元素用于在网页上绘制图形. 什么是 Canvas? HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像. 画布是一个矩形区域,您可以控制其每一像素. canv ...
- Python3解leetcode Best Time to Buy and Sell Stock II
问题描述: Say you have an array for which the ith element is the price of a given stock on day i. Design ...