个人项目作业
1.Github项目地址:https://github.com/13202008832/software-
2.在程序的各个模块的预计开发时间:
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
Planning |
计划 |
10 |
|
· Estimate |
· 估计这个任务需要多少时间 |
20 |
|
Development |
开发 |
120 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
20 |
|
· Design Spec |
· 生成设计文档 |
10 |
|
· Design Review |
· 设计复审 (和同事审核设计文档) |
10 |
|
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
10 |
|
· Design |
· 具体设计 |
30 |
|
· Coding |
· 具体编码 |
30 |
|
· Code Review |
· 代码复审 |
10 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
30 |
|
Reporting |
报告 |
20 |
|
· Test Report |
· 测试报告 |
20 |
|
· Size Measurement |
· 计算工作量 |
10 |
|
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
10 |
|
合计 |
|
360 |
|
3. 解题思路:
首先,对题目中的需求进行分析,思考每个模块的结构,考虑用什么编程语言,我用的是C语言编程,用C语言可以很快地达到需求。
4.设计实现过程:
代码一共含有4个函数(包含主函数)。其中CharCount、WordCount、LineCount 3个函数为主要功能函数,而main函数是用来调用3个函数。
5.代码说明:
头函数
#include "stdio.h" #include "stdlib.h"
主函数
1 void main() { 2 while(1){ FILE *fp; 3 int counts,c;//c为控制命令的输入变量 4 5 if((fp=fopen("D:\\test.c","r"))==0) { // D盘下test.c为该程序测试文件 6 printf("文件读取失败!\n"); 7 exit(0); 8 } 9 10 11 printf("WC程序功能: 1.-c 2.-w 3.-l 0.exit\n请选择您要进行的操作:1 or 2 or 3 or 0\n操作序号: "); 12 scanf("%d",&c); 13 printf("\n"); 14 do{ 15 16 switch(c){ 17 case 1: counts=CharCount(fp);printf("文件中的字符数为%d。\n",counts);break; 18 case 2: counts=WordCount(fp);printf("文件中的词数为%d。\n",counts);break; 19 case 3: counts=LineCount(fp);printf("文件中的行数为%d。\n",counts);break; 20 default:if(c==0)exit(0);printf("输入错误,请重新输入!\n操作序号: ");scanf("%d",&c);break; 21 } 22 }while(c!=1&&c!=2&&c!=3&&c!=0); 23 printf("\n\n"); 24 fclose(fp);} 25 }
功能函数
1.CharCount
1 int CharCount(FILE *fp) //计算文件中字符数 2 { 3 char ch; //变量ch用来存储文件中取出的字符 4 int charCounts=0; 5 6 while((ch=fgetc(fp))!=EOF) 7 { 8 9 charCounts++; 10 } 11 return charCounts; //返回字符数 12 }
2.LineCount
1 int LineCount(FILE *fp) //计算文件中行数 2 { 3 char ch; 4 int lineCounts=0; 5 6 while((ch=fgetc(fp))!=EOF) 7 { 8 if(ch=='\n') //用数换行符的方式计算文件中的行数 9 lineCounts++; 10 } 11 12 return lineCounts; 13 }
3.WordCount
1 int WordCount(FILE*fp){ //计算文件中词数 2 3 char ch; 4 int wordCounts=0,pd=0;//pd为0时表示不是词,pd为1时表示是词 5 6 while((ch=fgetc(fp))!=EOF) { 7 if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) { 8 if(pd==0)pd=1; 9 } else { 10 if(pd==1) { 11 wordCounts++; 12 pd=0; 13 } 14 } 15 } 16 17 18 19 return wordCounts; 20 }
6.测试文件
test.c
1 #include<stdio.h> 2 void main() { 3 4 printf("hello,world!"); 5 }
7.测试运行
操作界面
统计字符数
统计词数
统计行数
8.PSP实际花费时间
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
Planning |
计划 |
10 |
15 |
· Estimate |
· 估计这个任务需要多少时间 |
20 |
15 |
Development |
开发 |
120 |
90 |
· Analysis |
· 需求分析 (包括学习新技术) |
20 |
10 |
· Design Spec |
· 生成设计文档 |
10 |
10 |
· Design Review |
· 设计复审 (和同事审核设计文档) |
10 |
10 |
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
10 |
15 |
· Design |
· 具体设计 |
30 |
50 |
· Coding |
· 具体编码 |
30 |
40 |
· Code Review |
· 代码复审 |
10 |
10 |
· Test |
· 测试(自我测试,修改代码,提交修改) |
30 |
20 |
Reporting |
报告 |
20 |
30 |
· Test Report |
· 测试报告 |
20 |
20 |
· Size Measurement |
· 计算工作量 |
10 |
10 |
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
10 |
5 |
合计 |
|
360 |
350 |
9.项目小结
这次项目中我还有很多不足之处,只完成了WC程序的3个基本功能,制作成果比较简陋,制作过程中出现了很多bug,这是我练习的不够的表现,也有前期审题和规划时不够严谨的因素。
我会在接下来的项目中更加努力,做得更好。