软件的需求分析

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

  • 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. android studio 错误: InnerClass annotations are missing corresponding EnclosingMember annotations. Such InnerClass annotations are ignored

    android studio 错误: InnerClass annotations are missing corresponding EnclosingMember annotations. Suc ...

  2. sql优化常见的集中方法

    在sql查询中为了提高查询效率,我们常常会采取一些措施对查询语句进行sql优化,下面总结的一些方法,有需要的可以参考参考. 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 ord ...

  3. Mac svn使用学习-1-简介

    在Windows环境中,可以使用TortoiseSVN来搭建svn环境.但是由于Mac自带了svn的服务器端和客户端功能,因此可以直接使用svn功能. svn即subversion,Subversio ...

  4. Arthas开源项目

    本文主要围绕着Arthas是什么.能做什么.安装和使用等三个方面内容来讲解,希望对初学者和对此有兴趣的朋友有帮助. 一. Arthas是什么 文档地址: https://alibaba.github. ...

  5. OpenCV——边缘检测(sobel算子、Laplacian算子、scharr滤波器)

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  6. PAT B1007 素数对猜想 (20 分)

    让我们定义d​n​​为:d​n​​=p​n+1​​−p​n​​,其中p​i​​是第i个素数.显然有d​1​​=1,且对于n>1有d​n​​是偶数.“素数对猜想”认为“存在无穷多对相邻且差为2的素 ...

  7. hadoop集群部署配置补充

    /etc/hosts192.168.153.147 Hadoop-host192.168.153.146 Hadoopnode1 192.168.153.145 Hadoopnode2::1 loca ...

  8. P3195 [HNOI2008]玩具装箱TOY

    列出DP方程式:设f[i]表示分组完前i件物品的最小花费,为方便计算,设sum[i]表示是前i件物品的长度和. f[i]=min(f[j]+(sum[i]-sum[j]+i-j-L-1)^2) [0& ...

  9. asp.net mvc session锁问题 (转载)

    一.会话状态Session Session用于服务器端状态管理,使用Session之后,每个客户端都可以将实际的数据保存在服务器上,对于每个客户端的数据,将会生成一个对应的唯一的key(保存在客户端) ...

  10. 基于Python自动发送QQ群消息

    1.准备工作 此次测试基于python3,需要安装qqbot.bs4.requests库. qqbot项目地址:https://github.com/pandolia/qqbot.git pip qq ...