软件的需求分析

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

  • 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. docker swarm英文文档学习-1-概述

    参考https://docs.docker.com/engine/swarm/ Swarm mode overview群模式概述 Docker的当前版本包括集群模式,用于本地管理称为集群的Docker ...

  2. 【转】Python 可视化神器-Plotly Express

    转自:https://mp.weixin.qq.com/s/FNpNJSMK5Vs8pwi0PbbBzw 说明:图片无法直接复制,请查看原文 导读:Plotly Express 是一个新的高级 Pyt ...

  3. leetcode717—1-bit and 2-bit Characters

    We have two special characters. The first character can be represented by one bit 0. The second char ...

  4. Python2.7-shutil

    shutil 模块,高级文件操作模块,支持文件或文件夹的复制和删除 模块方法: shutil.copyfileobj(fsrc, fdst[, length]):将类文件对象(在python中打开的文 ...

  5. js基础知识入门总结

    1.第一个js程序 一个项目包括三部分:前端(html.css.js).数据库.后端技术 引入方式:页面中直接写,script标签引入 js事件绑定: <input type="but ...

  6. 使用Gitblit 在Windows2008 r2上部署Git Server(完整版)

    第一章 前言 使用gitblit搭建git server需要配置两个大件:java jdk.gitblit 本次搭建gitServer采用是当前最新版的两个版本,分别如下: jdk:Java SE D ...

  7. pip安装python包出错:Could not find a version that satisfies the requirement skimage (from versions: )

    今天用pip安装skimage时报错: 这是因为网络的问题,需要使用国内的镜像源来加速,比如豆瓣源 命令改为: pip install scikit-image -i http://pypi.doub ...

  8. python基础2之字符串、列表、字典、集合

    内容概要: 一.python2 or 3 二.字符串拼接 三.字符串 四.列表.元祖 五.字典 六.集合 七.练习 一.python2 or python3 目前大多使用python2.7,随着时间的 ...

  9. 原创zynq文章整理(MiZ702教程+例程)

    MiZ702教程+例程  网盘链接:  http://pan.baidu.com/s/1sj23yxv 不时会跟新版本,增加勘误之类的,请关注--

  10. 汇编 OR运算

    知识点:  OR运算  逻辑或  按位或 一.OR运算 12||1=1; 1||01=1; 0||0=0; || //逻辑或 | //按位或 int _tmain(int argc, _TCHA ...