统计程序中各种代码行数的课程设计

上传人:工**** 文档编号:457582169 上传时间:2023-06-02 格式:DOCX 页数:34 大小:198.56KB
返回 下载 相关 举报
统计程序中各种代码行数的课程设计_第1页
第1页 / 共34页
统计程序中各种代码行数的课程设计_第2页
第2页 / 共34页
统计程序中各种代码行数的课程设计_第3页
第3页 / 共34页
统计程序中各种代码行数的课程设计_第4页
第4页 / 共34页
统计程序中各种代码行数的课程设计_第5页
第5页 / 共34页
点击查看更多>>
资源描述

《统计程序中各种代码行数的课程设计》由会员分享,可在线阅读,更多相关《统计程序中各种代码行数的课程设计(34页珍藏版)》请在金锄头文库上搜索。

1、统计程序中各种代码行数的课 程设计需求分析1)问题描述读入一个C程序,统计程序中代码、注释和 空行数以及函数的个数和平均行数,并利用统 计信息分析评价该程序风格。2)基本要求如下:(1)、把C程序文件按字符顺序读入源程序;(2)、边读入程序,边识别统计代码行、注释 行和空行,同时还要识别函数的开始和结束,以便统计其个数及平均行数。(3)、程序风格分为代码注释和空行三方面。每方面分A、B、C、D四个等级。A BCD代码(函数的平均长度)1015行89或162057或212424注释(占总行数比例)1525%1014或 2630%59或3135%35%空行(占总行数比率)1525%1014或263

2、0%59或 31 35%35%3)输入输出范例以下是对程序文件 ProgAnal.C分析的输出结果示例:The resultsofan alys ingprogramfile ProgA nal.C:Lines of code:180Lines of comme nts:63Bia nk lin es:52CodeComme ntsSpace61%21%18%The program in cludes 9 fun cti ons.The average len gth of a secti on of code is 12.9 lin es.GradeA:Excelle ntrouti ne

3、sizestyle.GradeA:Excelle ntcomme nti ngstyle.Grade A:Excelle ntwhite spacestyle.1概要设计1).头文件引用与宏定义:#i nclude #i nclude #i nclude #defi neTRUE1#defi neFALSE0#defi neBOOLint#defi ne MAXSIZE 5000#defi ne COUNT 20/ /可以统计的最大 的文件个数#defi ne LEN 20 / 文件名的最 大长度2).所用存储结构 /函数属性结构typedef struct char file name20;

4、 /每一个函数的名字i nt length;/ 每一个函数的长度i nt pos; /每一个函数的位置Fu n;/统计结构的声明typedef struct in t comme nts; /纯注释的个数i nt comment; /混合注释个数i nt blank; /空行的个数Fun funMAXSIZE;/ 函数的属性i nt others;/除去函数中代码外其余的代码个数i nt funcount; /函数的个数An aly;2.详细设计1).函数功能及声明BOOL StrEmpty(char *s)/S 是不是空 int Find(char *s1,char *s2) 查找 S1 中

5、 是否有值为S2的子串void HaveLi ne(FILE *fp,char *s)重文件中获取一行char* IgnoreB(char *s) 截断一行的空字 符int IsCom(char *s)判断一行是不是注释 BOOL IsBla nk(char *s) 判断一行是不是 空格BOOLsFunB(char *s)判断一行是否是函 数的开头void PrintMax(Analy *An) 打印最大函数的信息void prin tR(i nt aver ,int comc,i ntblanks )/打印代码风格级别void print(An aly *An)/void checkfile

6、(char *filename,int i)/ 检测文件是否存在BOOLGetIn(int*n)/规范输入的数据,只能为数字void an aly(charfile nameCOUNTLEN,i nt n)/分析单个文件void savelog()/ 保存日志2)详细源代码/ 检测是否为空串BOOL StrEmpty(char *s)i f(s0=0) return TRUE;r eturn FALSE;/查看S1中是否有值为S2的子串,若有则 返回第一个子串的位置,若无则返回 -1 ; int Find(char *s1,char *s2)i nt i = 0,j = 0;i f(strle

7、n(s1) pos1 & posc j ? j : i;else if (i = -1) i = j;else if (1 = -1 & j = -1) return FALSE;if (i pos)return FALSE;s = & si;s = Igno reB(s);pos2 = Fin d(s,();if(*s = 0 | *s = ( |pos2 pos) return FALSE;return TRUE;/打印最大的函数属性void Prin tMax(A naly *A n)/ FILE *fp;int i,j = 0;/ int len;for(i = 1;i funcoun

8、t ;i+)if(A n-fun j.le ngth fu nie ngth)/ j = i;找出最大的函数的位置if(An-fu nj.le ngth fun j.pos fu nj.le ngth);/打印长度prin tf(The pos of len gthestfunction is in %s the %dth lin en,A n-fu nj.file name,A n-fu nj.po s);/打印出函数所在的文件和位置prin tf( The len gth of len gthest fun cti on have %d linesn,A n-fu nj.le ngth);

9、/打印长度void printR(intaver ,int comc,int blanks )/按代码级别判定标准输出分析结果int i;char Grade415=Excelle nt,Good,So-So,Bad;定义四个级别段/判定代码的级别if (aver =10)i = 0;else if(aver = 16) | aver= 8)i = 1;else if(aver = 5) | aver =21)i = 2;else if (aver 24)i = 3;prin tf(Grade %s routi ne codestylen,Gradei);/判定注释的级别if (comc= 15)i = 0;else if(comc = 10) | comc=26)i = 1;else if(comc = 5) | comc =31)i = 2;else if(comc 35)i = 3;prin tf( Grade %s routi ne comme nti ng sty

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号