软件质量测试 第二周 wordcount 作业

一.github地址

https://github.com/WKX121/WC

二.PSP

PSP表格

PSP2.1

PSP阶段

预估耗时

(分钟)

实际耗时

(分钟)

Planning

计划

 25  25

· Estimate

· 估计这个任务需要多少时间

 25   25

Development

开发

300  340

· Analysis

· 需求分析 (包括学习新技术)

 40  40

· Design Spec

· 生成设计文档

 -  -

· Design Review

· 设计复审 (和同事审核设计文档)

 -  -

· Coding Standard

· 代码规范 (为目前的开发制定合适的规范)

 -  -

· Design

· 具体设计

 40  40

· Coding

· 具体编码

 180 200

· Code Review

· 代码复审

 40  60

· Test

· 测试(自我测试,修改代码,提交修改)

40  100

Reporting

报告

 120  180

· Test Report

· 测试报告

 60  60

· Size Measurement

· 计算工作量

 30  20

· Postmortem & Process Improvement Plan

· 事后总结, 并提出过程改进计划

 60  60
 

合计

 960  1150

三.思路

1.根据需求首先最传入main函数中的args解析出对应的命令,文件名

2.-c命令通过每次fgetc使wc_char加一

3.-w通过对空格和,的判断使wc_word加一

4.-l通过对/n判断使wc_line加一

 

四.程序的设计实现

通过对args不同数值的情况来处理各种统计模式,看对应哪个命令就调用相应的处理程序进行处理。然后将计数后的结果输出到指定txt文件当中。

五.代码说明

 

 

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int main(int argc, char * argv[])
{
    int wc_char = 0;
    int wc_word = 1;
    int wc_line = 1;
    char filename[80];
    FILE *fp = NULL;
    if (argc == 3)
    {
        fp = fopen(argv[2], "r");
        if (fp == NULL)
        {
            printf("打开有误!\n");
            printf("请按enter键继续....");
            _getch();
            exit(0);
            //...
        }
            char ch;
            
           
            while (1)
         {   ch = fgetc(fp);
              wc_char++;
              if (ch == ' '||ch==',')
            {
                wc_word++;
            }
            else if (ch == '\n')
            {
                wc_word++;
                wc_line++;
            }
            else if (ch == EOF)
            {
                break;
            }
             
          }
        if (strcmp(argv[1],"-c")==0)
        {
            printf("The char count is %d\n", wc_char);
            fp = fopen("result.txt","w");
            fprintf(fp,"字符数:%d\n", wc_char); 
        }
        else if (strcmp(argv[1],"-w")==0)
        {
            printf("The word count is %d\n", wc_word);
            fp = fopen("result.txt","w");
            fprintf(fp,"单词数:%d\n", wc_word); 
        }
        else if (strcmp(argv[1],"-l")==0)
        {
            printf("The line count is %d\n", wc_line);
            fp = fopen("result.txt","w");
            fprintf(fp,"行数:%d\n", wc_line); 
        }
        
        fclose(fp);
    }
    if (argc == 4)
    {
        fp = fopen(argv[3], "r");
        if (fp == NULL)
        {
            printf("打开有误!\n");
            printf("请按enter键继续....");
            _getch();
            exit(0);
            //...
        }
            char ch;
            
           
            while (1)
         {   ch = fgetc(fp);
              wc_char++;
              if (ch == ' '||ch==',')
            {
                wc_word++;
            }
            else if (ch == '\n')
            {
                wc_word++;
                wc_line++;
            }
            else if (ch == EOF)
            {
                break;
            }
             
          }
        if (strcmp(argv[1],"-c")==0&&strcmp(argv[2],"-w")==0)
        {
            printf("The char count is %d\n", wc_char);
            printf("The word count is %d\n", wc_word);
            fp = fopen("result.txt","w");
            fprintf(fp,"字符数:%d\n单词数:%d\n", wc_char,wc_word); 
        }
        if (strcmp(argv[1],"-c")==0&&strcmp(argv[2],"-l")==0)
        {
            printf("The char count is %d\n", wc_char);
            printf("The line count is %d\n", wc_line);
            fp = fopen("result.txt","w");
            fprintf(fp,"字符数%d\n行数:%d\n", wc_char,wc_line); 
        }
        if (strcmp(argv[1],"-w")==0&&strcmp(argv[2],"-l")==0)
        {
            printf("The word count is %d\n", wc_word);
            printf("The line count is %d\n", wc_line);
            fp = fopen("result.txt","w");
            fprintf(fp,"单词数:%d\n行数:%d\n", wc_word,wc_line); 
        }
        
        fclose(fp);
    }
    if (argc == 5)
    {
        fp = fopen(argv[4], "r");
        if (fp == NULL)
        {
            printf("打开有误!\n");
            printf("请按enter键继续....");
            _getch();
            exit(0);
            //...
        }
            char ch;
            
           
            while (1)
         {   ch = fgetc(fp);
              wc_char++;
              if (ch == ' '||ch==',')
            {
                wc_word++;
            }
            else if (ch == '\n')
            {
                wc_word++;
                wc_line++;
            }
            else if (ch == EOF)
            {
                break;
            }
             
          }
        if (strcmp(argv[1],"-c")==0)
        {
            printf("The char count is %d\n", wc_char);
            
        }
        else if (strcmp(argv[1],"-w")==0)
        {
            printf("The word count is %d\n", wc_word);
           
        }
        else if (strcmp(argv[1],"-l")==0)
        {
            printf("The line count is %d\n", wc_line);
            
        }
        if (strcmp(argv[2],"-c")==0)
        {
            printf("The char count is %d\n", wc_char);
           
        }
        else if (strcmp(argv[2],"-w")==0)
        {
            printf("The word count is %d\n", wc_word);
            
        }
        else if (strcmp(argv[2],"-l")==0)
        {
            printf("The line count is %d\n", wc_line);
            
        }
        if (strcmp(argv[3],"-c")==0)
        {
            printf("The char count is %d\n", wc_char);
           
        }
        else if (strcmp(argv[3],"-w")==0)
        {
            printf("The word count is %d\n", wc_word);
            
        }
        else if (strcmp(argv[3],"-l")==0)
        {
            printf("The line count is %d\n", wc_line);
           
        }
         fp = fopen("result.txt","w");
            fprintf(fp,"字符数:%d\n单词数:%d\n行数:%d\n", wc_char,wc_word,wc_line); 
        fclose(fp);
    }
}

 

 

六.测试设计过程

10个测试:

1.-c

2.-w

3.-l

4.-c -w

5.-c -l

6.-w -l

7.-c -w -l

8.复杂符号测试

9.代码测试

10.复杂代码测试

七.参考文献

http://www.cnblogs.com/cool125/p/7560596.html

posted @ 2018-03-20 22:07  安兹乌尔恭  阅读(177)  评论(2编辑  收藏  举报