2021年4月2日 作业

这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018/
这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018/homework/11879
这个作业的目标 使用码云
其他参考文献 https://www.cnblogs.com/greyzeng/p/4370439.html
其他参考文献 https://www.jianshu.com/p/94c4b8e8593c?utm_campaign=haruki&utm_content=note&utm_medium=reader_share&utm_source=weixin

1.Gitee地址

https://gitee.com/luo3090306768/study.git

2.代码规则

https://www.cnblogs.com/xinz/archive/2011/11/20/2255830.html

3.PSP表格

PSP Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟)
Planning 计划 1 1
• Estimate • 估计这个任务需要多少时间 1 7
Development 开发 1 1
• Analysis • 需求分析 (包括学习新技术) 3 4
• Design Spec • 生成设计文档 3 3
• Design Review • 设计复审 2 2
• Coding Standard • 代码规范 (为目前的开发制定合适的规范) 3 30
• Design • 具体设计 12 6
• Coding • 具体编码 24 32
• Code Review • 代码复审 3 3
• Test • 测试(自我测试,修改代码,提交修改) 6 30
Reporting 报告 1 1
• Test Repor • 测试报告 4 3
• Size Measurement • 计算工作量 2 1
• Postmortem & Process Improvement Plan • 事后总结, 并提出过程改进计划 3 1
合计 660 41 80

4.代码实现

统计文件的字符数(对应输出第一行):

if((fpr = fopen(name,"r")) == NULL)
    {
        printf("Can't open %s\n",name);
        exit(1);
    }
    while((ch = fgetc(fpr)) != EOF)
    {
       if(ch>=48 &&ch<=57)//数字的ASCII码
       {
            number++;
       }
       if((ch>=65&&ch<=90) || (ch>=97&&ch<=122))//字母的ASCII码
       {
           character++;
       }
       if(ch == 32)//空格的ASCII码
       {
           space++;
       }
       total++;

截图

统计文件的单词总数(对应输出第二行),单词:至少以4个英文字母开头,跟上字母数字符号,单词以分隔符分割,不区分大小写

fscanf(fp,"%s",a[i].str);
    a[i].n++;  
    for(j=0;j<i;j++)
        if(strcmp(a[i].str,a[j].str)==0) 
        {
            if(a[j].n!=0)a[j].n++; 
            a[i].n=0; 
        }
        times++; 
        if(fgetc(fp)==EOF)break;           
    }
    for(i=0;i<times-1;i++)  
    for(j=0;j<times-1-i;j++)
        if(a[j].n<a[j+1].n) 
        {       
            t=a[j];
            a[j]=a[j+1];
            a[j+1]=t; 
        }
        for(i=0;i<10;i++) 
            printf("%s  %d\n",a[i].str,a[i].n);

截图

统计文件的有效行数(对应输出第三行)

File f = new File("C:/Users/UserName/Desktop/ed.txt");
		if(!f.exists()) {
			p("不存在该文件");
			System.exit(-1);
		}
		BufferedReader br = null;
		boolean comment;
		try {
			br = new BufferedReader(new FileReader(f));
			String line;
			comment = false;
			while((line = br.readLine()) != null) {
				normalLines ++; //只要非空就行数加1
				if(line.matches("^\\s*$"))
					whiteLines ++; //匹配空行加1
				else if(true == comment) {
					commentLines ++; //只要还在注释行则加1
					if(line.endsWith("*/"))
						comment = false; //退出注释行置为false
				}
				else if(line.startsWith("//"))
					commentLines ++; //注释行
				else if(line.startsWith("/*")) {
					commentLines ++;
					if(!line.endsWith("*/"))
						comment = true; //开始进入注释块
				}
			}
 
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if(br != null) {
				try {
					br.close();
					br = null;
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

5.计算模块部分异常处理说明

编码问题会乱码需统一编码utf-8
输出文件改成utf-8格式为正常。

6.心路历程与收获

本次作业耗时太多,以前的文件知识基本忘完了,没有什么基础所以搞得很粗糙,大量搜集信息
学习课本上的知识是不够的,还要经常自己动手,有较强的实践能力。只有多动
手,经常编写程序,才能发现我们学习上的漏洞和自己的不足,解决这些问题。

posted @ 2021-04-02 17:59  罗宇梁  阅读(47)  评论(0编辑  收藏  举报