个人项目

1、项目网址:https://github.com/1952168900/WC1

2、预估耗费时间

PSP2.1

Personal Software Process Stages

预估耗时(分钟)

实际耗时(分钟)

Planning

计划

 15

· Estimate

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

 15

Development

开发

 240

· Analysis

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

 30

· Design Spec

· 生成设计文档

 10

· Design Review

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

 10

· Coding Standard

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

 10

· Design

· 具体设计

 20

· Coding

· 具体编码

 60

· Code Review

· 代码复审

 20

· Test

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

 30

Reporting

报告

 60

· Test Report

· 测试报告

 30

· Size Measurement

· 计算工作量

 10

· Postmortem & Process Improvement Plan

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

 10

合计

 570

3、解题思路
一开始我是在选用C语言还是JAVA中纠结的,选择了C语言的原因是JAVA学的还不多,C语言使用更熟练。接下来定下了通过主函数来调用其他的函数来实现要求的思路。之后就遇到了难点,如何调用其他的文件,所以就上网查了相关资料,学到了fclose、fopen、fgetc等函数。由于时间和个人能力有限的原因,只能实现三个基本功能。

4、设计实现过程
在有了上述的思路之后,我设计了四个函数,一个主函数,三个子函数,每个子函数对应一个功能的实现。在主函数提醒使用者输入对应的指令和调用文件的地址后,通过循环语句和swtich语句来循环调用对应指令的子函数。在子函数实现文件的调用和数据的输出。

5、代码说明
字符数计算函数
int Countcharacters(char File[]) { //字符数计算 
int characters = 0;
FILE *file_Read = fopen(File,"rt");
char chr = ' '; 
if(file_Read == NULL) {
printf("文件地址错误,请关闭重试 ");
return 0; 
}
while((chr = fgetc(file_Read)) != EOF) {
if(isspace(chr) == NULL)characters++;
}
fclose(file_Read);
printf("字符个数是%d ",characters);
return 1;
}

单词数计算函数
int Countwords(char File[]) {//单词数计算
int words = 0; 
FILE *file_Read = fopen(File,"rt");
char chr = ' '; 
if(file_Read == NULL) {
printf("文件地址错误,请关闭重试 ");
return 0; 
}
while((chr = fgetc(file_Read)) != EOF) {
while((chr >= 'a' && chr <= 'z' )|| (chr >= 'A' && chr <= 'Z')||chr == '-')
chr = fgetc(file_Read);
words++;
}
fclose(file_Read);
printf("文件单词数为%d ",words);
return 1;
}

行数计算函数
int Countlines(char File[]) { //行数计算 
int lines = 0;
int sign = 0;
FILE *file_Read = fopen(File,"rt");
char chr = ' '; 
if(file_Read == NULL) {
printf("文件地址错误,请关闭重试 ");
return 0; 
}
while((chr = fgetc(file_Read)) != EOF) {
if(sign == 0)lines++;
sign++;
if(chr == ' ')
lines++;
}
fclose(file_Read);
printf("统计行数为%d ",lines);
return 1;
}

主函数

int main() {
int tag;
char control;
char File[100];
int number = 1;
printf(" 指令表: c 统计字符数,w 统计单词数,l 统计行数 r 退出程序 ");
printf("请输入用户命令wc.ext-: ");
scanf("%c",&control);
printf("请正确输入要查找的文件地址: ");
scanf("%s",File);
while(number) {
switch(control) {
case 'c':tag=Countcharacters(File);
if(tag == 0)return 0;
break;
case 'w':tag=Countwords(File);
if(tag == 0)return 0;
break;
case 'l':tag=Countlines(File);
if(tag == 0)return 0;
break;
case 'r':return 0;
default :printf("请重新输入用户命令wc.ext-: ");
}
scanf("%c",&control);
}
}

6、测试运行

使用了四个TXT文件来测试运行

 

 

7、实际消耗时间

PSP2.1

Personal Software Process Stages

预估耗时(分钟)

实际耗时(分钟)

Planning

计划

 15

 18

· Estimate

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

 15

 10

Development

开发

 240

 300

· Analysis

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

 30

 60

· Design Spec

· 生成设计文档

 10

 15

· Design Review

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

 10

 10

· Coding Standard

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

 10

 15

· Design

· 具体设计

 20

 10

· Coding

· 具体编码

 60

 50

· Code Review

· 代码复审

 20

 25

· Test

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

 30

 40

Reporting

报告

 60

 75

· Test Report

· 测试报告

 30

 5

· Size Measurement

· 计算工作量

 10

 10

· Postmortem & Process Improvement Plan

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

 10

 10

合计

 570

 653

8、项目小结

(1)正式开发所用的代码不难,但是在实际操作过程中出现了不少BUG,导致开发时间过长,从中也学习到了很多知识;

(2)第一次使用GITHUB上传文件,在学习使用过程中也浪费了不少时间;

(3)由于个人能力有限导致了附加功能未能实现,仍需继续学习提升个人能力。

原文地址:https://www.cnblogs.com/zl1952168900/p/12497453.html