软件的需求分析

程序处理用户需求的模式为:

  • wc.exe [parameter][filename]

在[parameter]中,用户通过输入参数与程序交互,需实现的功能如下:

1、基本功能

  • 支持 -c  统计文件字符数
  • 支持 -w 统计文件单词数
  • 支持 -l  统计文件总行数

2、拓展功能

  • 支持 -a 返回高级选项(代码行 空行 注释行)
  • 支持 -s 递归处理符合条件的文件

3、高级功能

  • 支持 -x 程序以图形界面与用户交互

[filename] 是待处理文件名。

从周五到今天一直在弄VS 2013,感觉有的那几个错误我都遇到了,算了算20多个小时了,郁闷的不行。不能单步调试、新建不了项目,卸载修复各种问题,太不容易了。

总算在作业结束之前把基本的功能写出来了,下面分解一下程序。

主程序主要是创建对象,把输入的字符串已空格为间隔拆分成几个字符串,并记录最后一个字符串为文件路径。最后按照输入命令一次返回不同值,执行不同功能。

            Wc c = new Wc();//创建对象
Console.Write("wc.exe");
string msg = Console.ReadLine();
string[] newm = msg.Split(new char[] { ' ' });//去掉空格 拆分成几个字符串
int n = newm.Length;
string str = newm[n - ];//记录文件路径
foreach (string i in newm)
{
if (i == "-c")
{
c.Read(str, );//字符数目功能
}
else if (i == "-w")
{
c.Read(str, );//单词数
}
else if (i == "-l")
{
c.Read(str, );//行数目
}

Read函数首先访问传过来的字符串路径,并打开。

        //byte[] byData = new byte[];//应该注释掉,一开始用的byte类型,后来发现有点问题
FileStream file = new FileStream(a, FileMode.Open);
StreamReader sr = new StreamReader(file);//访问文件并读取
//file.Read(byData, 0, 10000);
switch (b)
{

switch  结构 统计出各功能数目。

case :
{
/*while (byData[i] != '\0')
{
c++;
i++;
}*/
int Ichar = ;
while ((Ichar = sr.Read()) != -) // 不再有可用的字符,则为 -1
{
if (Ichar != ' ')
{
c++;
}
}
Console.WriteLine("字符数为:" + c);
file.Close();
} break;
case :
{
int Ichar = 0; //增加 char[] no = { ' ', '\n', '{', '}', '(', ')', '=', '+', '_', '*', '%' };
            while ((Ichar = sr.Read()) != -)
                    {
if (Ichar == ' ' || Ichar == '\n')//这我在想想更准确的判断方法 - -!
                        {                               //  for (int ss = 0; ss < 11; ss++)
w++; // {
} // if (Ichar ==no[ss]) 这个更加准确!
}
Console.WriteLine("单词数为:" + w);
file.Close();
} break;
case :
{
int Ichar = ;
while ((Ichar = sr.Read()) != -)
{
if (sr.ReadLine() != null)
{
l++;
}
}
Console.WriteLine("行数为:" + l);
file.Close();
} break;
}

下面贴上文本与结果。

增加-a 高级功能,首先在主函数添加代码,使程序能跳转到read函数。

 else if(i=="-a")
{
c.Read(str, );
}

在read函数中添加case 5,增加三个行数功能。

int Line_daima = ;
int Line_kong = ;
int Line_zhushi = ;//初始化三个行数变量
string stra;
while ((stra = sr.ReadLine())!=null)//读到末尾停止
{ if (stra=="")//百度了好多次,总算明白了readline函数对空行和末尾的区别
{
Line_kong++;
}
else if((stra.IndexOf('/'))>-)//判断字符串stra中是否存在’/‘字符
{
Line_zhushi++;
}
//int cc = s.IndexOf("//");
//string[] newn=str.Split(new char[]{'//'});
// if ( > -1)
// {
// Line_zhushi++;
// } //中间这段是错误案例,还没想好怎么能写出来。
else
Line_daima++;
}
Console.WriteLine("空行数为:"+Line_kong);
Console.WriteLine("注释行数为:"+Line_zhushi);
Console.WriteLine("代码行数为:"+Line_daima);
file.Close(); //这个很重要,一定要关闭访问过的文件。
}break;

实现项目WC的更多相关文章

  1. 个人项目-wc

    个人项目-WC   (C语言) 一.Github地址:https://github.com/Lin-J-F/WC 二.PSP表格 PSP2.1 Personal Software Process St ...

  2. 实践简单的项目WC

    #include<iostream> #include<fstream> #include<string> #include<Windows.h> us ...

  3. 个人项目——wc源程序特征统计

    这一次要做的项目是wc——统计程序文件特征的命令行程序. 根据需求需求得到的模式为:wc.exe [parameter][filename] 在[parameter]中,用户通过输入参数与程序交互,需 ...

  4. 个人项目-WC(C/C++ 兼容Linux和Windows)

    一.Github地址 https://github.com/S-TRAVELER/WC 实现的功能: 支持 -c 支持 -w 支持 -l 支持 -s 支持 -a 图形界面 多参数(文件名或通配符表达式 ...

  5. 个人项目-WC (java实现)

    一.Github地址:https://github.com/734635746/WC 二.PSP表格 PSP2.1 Personal Software Process Stages 预估耗时(分钟) ...

  6. 个人项目-WC(Java实现)

    一.Github项目地址: https://github.com/kestrelcjx/-WC-Java- 二.PSP表格 PSP2.1 Personal Software Process Stage ...

  7. 个人项目 wc(java实现)

    一.Github网址: https://github.com/Clarazhangbw/Wc.exe 二.PSP表 PSP2.1 Personal Software Process Stages 预估 ...

  8. 个人项目WC(Python实现)

    一.GitHub地址 https://github.com/hoka-17/WC 二.PSP表格 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际 ...

  9. 个人项目—WC

     一,Github地址:https://github.com/mushan520/WC.git 二.PSP表格: PSP2.1 Personal Software Process Stages 预估耗 ...

随机推荐

  1. [SQL123] Oracle SQL 统计一定时间间隔内的数据

    --Group by State_ts "per X minutes"select to_char(state_ts, 'hh24')||':'||floor(to_char(st ...

  2. MP实战系列(十五)之执行分析插件

    SQL 执行分析拦截器[ 目前只支持 MYSQL-5.6.3 以上版本 ],作用是分析 处理 DELETE UPDATE 语句, 防止小白或者恶意 delete update 全表操作! 这里我引用M ...

  3. XML 读写(XmlDocument、XPathNavigator、XDocument)

    内存中的 XML 处理 基于流的 XML 处理提供了最小的负载,但也只提供了最小的灵活性.在很多 XML 处理场景里,你不会在这么低的层次下工作. 对内存中的 XML 的处理则更加方便,但没有单一.标 ...

  4. WorldWind源码剖析系列:相机类CameraBase

    相机基类CameraBase PluginSDK中的相机类CameraBase是三维计算机图形学中的概念.观察者在三维场景中漫游时,通过眼睛看到的场景和相机拍摄过程非常一致.实际上,Direct3D和 ...

  5. windows10 + anaconda + tensorflow-1.5.0 + python-3.6 + keras-2.2.4配置和安装

    windows10 + anaconda + tensorflow-1.5.0 + python-3.6 + keras-2.2.4配置和安装 (base) C:\Users\jiangshan> ...

  6. css动画,展开折叠图标

    @keyframes packupArrowFlow { 0% { bottom:; } 70% { bottom: 10px; } } @-webkit-keyframes packupArrowF ...

  7. Maltego——互联网情报聚合工具初探(转)

    有时候你可曾想过,从一个Email,或者Twitter,或是网站,甚至姓名等等,能找到一个人千丝万缕的联系,并把这些联系整合,利用起来?Maltego就是这样一款优秀而强大的工具.Maltego允许从 ...

  8. C# online update demo

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  9. Luogu P1484 种树

    这道题目还是比较简单的 首先题目的意思就让我们很轻易地想到DP 我们设f[i][j]表示前i个坑中种j棵树的最大利益,则有: f[i][j]=max(f[i-1][j],f[i-2][j-1]+a[i ...

  10. VS相关

    快速显示函数名称 ctrl+alt+T 显示函数参数说明 ctrl+shift+space,光标放在函数里面 link 1123错误,vs2010的问题. 点击工程-属性-ManifestTool-I ...