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 ...
随机推荐
- c语言学习的第11天 指针
#include<stdio.h> int main(void) { int * p; int i=3; int j; p=&i; j=*p; printf("i=%d, ...
- MySQL Unable to convert MySQL date/time value to System.DateTime的解决办法
在连接串中加入 Convert Zero Datetime=True
- Linux_异常_04_ftp: command not found...
今天在centos上使用ftp命令连接本机的FTP服务器(本机FTP服务使用Vsftpd搭建),出现如下的错误提示:-bash: ftp: command not found 查询相关资料,发现很有可 ...
- listen 68 Theoretical Physicist Stephen Hawking Dies at 76
World-renowned British physicist Stephen Hawking, who sought to understand a range of cosmic topics ...
- unity3d mvvm c#
using UnityEngine; using System.Collections; public interface IState { void BeforEnter(); void Befor ...
- HBASE---shangxueT
- kettle结合MySQL生成保留最近6个月月度报告_20161009
之前计算用户ID各月的金额(各月在列字段),用的是下面代码 ,b.金额,,b.金额,,b.金额,NULL)) AS 9月金额 FROM ( SELECT city AS 城市,DATE_FORMAT( ...
- ACM学习历程—Hihocoder 1177 顺子(模拟 && 排序 && gcd)(hihoCoder挑战赛12)
时间限制:6000ms 单点时限:1000ms 内存限制:256MB 描述 你在赌场里玩梭哈,已经被发了4张牌,现在你想要知道发下一张牌后你得到顺子的概率是多少? 假定赌场使用的是一副牌,四种 ...
- 打开关闭tomcat的目录浏览功能
目录浏览功能 conf/web.xml中init-param中有对于listing的定义,设置为true即可实现tomcat的目录浏览: tomcat的管理用户设置 conf/tomcat-users ...
- Wmware Player中Linux挂载U盘
菜单(Player)中有一项是可移动设备,中选择U盘,然后选择连接(断开主机), 然后在命令行中敲入 fdisk -l 正常情况下是sda是硬盘的信息,然后将会看到一个单蹦的sdb4的信息(sdb4可 ...