zoukankan      html  css  js  c++  java
  • 结对项目:代码复审+PSP

    一、代码复审

           首先我从代码风格规范和程序修改两方面进行审查。

    (一)代码风格规范修改###

    1 . 代码的部分未缩进:在用markdown粘贴代码时,需要后期tab,无形中加大工作量。

    2 . 命名不确切:定义的有a,b,m,n等,在此用英文释义表示,更改为“分子numerator、分母denominator”。

    int a,b,m,n; //修改前
    char c; 
    
    int num1,den1,num2,den2,t;//修改后
    char import; 
    

    3 . 注释过少:重要的语句并无解释,在此有加入,可移至博文底端附录代码部分。

    (二)程序修改###

    1 . 选取的分子随机数很可能会大于分母:使分子的取值范围缩小至分母数值内。

    		den1=rand()%100;
            num1=rand()%den1; 
            den2=rand()%100;
            num2=rand()%den2; 
    

    2 . 取分母的随机数可能为0:可添加if语句if(den1!=0||den2!=0),保证其取值为真分数时正常出题,再加以else语句,将分子与分母用 t 顺序转换,成为真分数。

            switch(import){ 
          		if(den1!=0||den2!=0){  
    	          	case 0:printf("%d+%d=
    ",den1,den2);break;
    				case 1:printf("%d-%d=
    ",den1,den2);break;
    				case 2:printf("%d*%d=
    ",den1,den2);break;
    				case 3:printf("%d/%d=
    ",den1,den2);break;
    				case 4:printf("(%d/%d)+(%d/%d)=
    ",num1,den1,num2,den2);break;
    				case 5:printf("(%d/%d)-(%d/%d)=
    ",num1,den1,num2,den2);break;
    				case 6:printf("(%d/%d)*(%d/%d)=
    ",num1,den1,num2,den2);break;
    				case 7:printf("(%d/%d)/(%d/%d)=
    ",num1,den1,num2,den2);break;
    	        }
    	        else{         
        			t=den1; 
        			den1=num1;
        			num1=t;
        			
        			t=den2;
        			den2=num2;
        			num2=t;
      			    switch(import){ 
    						case 0:printf("%d+%d=
    ",den1,den2);break;
    						case 1:printf("%d-%d=
    ",den1,den2);break;
    						case 2:printf("%d*%d=
    ",den1,den2);break;
    						case 3:printf("%d/%d=
    ",den1,den2);break;
    						case 4:printf("(%d/%d)+(%d/%d)=
    ",num1,den1,num2,den2);break;
    						case 5:printf("(%d/%d)-(%d/%d)=
    ",num1,den1,num2,den2);break;
    						case 6:printf("(%d/%d)*(%d/%d)=
    ",num1,den1,num2,den2);break;
    						case 7:printf("(%d/%d)/(%d/%d)=
    ",num1,den1,num2,den2);break;
    				} 
        		} 
           } 
    

    3 .题目形式单一:只有真分数运算,所以我加入了整数与其混合。使用import=rand()%8 语句任取题目。

            import=rand()%8;  
    

    (三)代码对比

    注:修改后的程序,标记为(改)。

    修改后代码:

    #include<stdio.h>
    #include <stdlib.h> 
    #include <time.h> 
    int main()
    {
    int i,j;
    printf("请输入题目的数量:");
    scanf("%d",&j);   
    int num1,den1,num2,den2,t;//分子numerator  分母denominator  转换t (改) 
    char import;   //输入的数量 
    srand((unsigned)time(NULL));  //取随机数 
    for(i=0;i<j;i++){
            den1=rand()%100;
            num1=rand()%den1;  //保证分子<分母 (改) 
            den2=rand()%100;
            num2=rand()%den2; 
            import=rand()%8;  //任取题目 (改) 
            switch(import){ 
          		if(den1!=0||den2!=0){  
    	          	case 0:printf("%d+%d=
    ",den1,den2);break;
    				case 1:printf("%d-%d=
    ",den1,den2);break;
    				case 2:printf("%d*%d=
    ",den1,den2);break;
    				case 3:printf("%d/%d=
    ",den1,den2);break;
    				case 4:printf("(%d/%d)+(%d/%d)=
    ",num1,den1,num2,den2);break;
    				case 5:printf("(%d/%d)-(%d/%d)=
    ",num1,den1,num2,den2);break;
    				case 6:printf("(%d/%d)*(%d/%d)=
    ",num1,den1,num2,den2);break;
    				case 7:printf("(%d/%d)/(%d/%d)=
    ",num1,den1,num2,den2);break;
    	        }
    	        else{          //保证分子< 分母 (改) 
        			t=den1; 
        			den1=num1;
        			num1=t;
        			
        			t=den2;
        			den2=num2;
        			num2=t;
      			    switch(import){ 
    						case 0:printf("%d+%d=
    ",den1,den2);break;
    						case 1:printf("%d-%d=
    ",den1,den2);break;
    						case 2:printf("%d*%d=
    ",den1,den2);break;
    						case 3:printf("%d/%d=
    ",den1,den2);break;
    						case 4:printf("(%d/%d)+(%d/%d)=
    ",num1,den1,num2,den2);break;
    						case 5:printf("(%d/%d)-(%d/%d)=
    ",num1,den1,num2,den2);break;
    						case 6:printf("(%d/%d)*(%d/%d)=
    ",num1,den1,num2,den2);break;
    						case 7:printf("(%d/%d)/(%d/%d)=
    ",num1,den1,num2,den2);break;
    				} 
        		} 
           } 
    	}
    }
    

    原始代码:

    #include<stdio.h>
    #include <stdlib.h> 
    #include <time.h> 
    int main()
    {
    int i,j;
    printf("请输入题目的数量:");
    scanf("%d",&j);   
    int a,b,m,n; 
    char c; 
    srand((unsigned)time(NULL));
    for(i=0;i<j;i++){
            a=rand()%100;
            b=rand()%100;
            m=rand()%100;
            n=rand()%100;
            c=rand()%4;
            switch(c){
                case 0:c='+';break;
                case 1:c='-';break; 
                case 2:c='*';break;
                case 3:c='/';break;
            }
        printf("%d/%d%c%d/%d=
    ",a,m,c,b,n);
        }
    }
    

    二、PSP记录个人项目耗时情况

    Data Start End Total(min) Task Remarks
    2016/3/10 11:00 11:30 30 讨论程序需要的模块 finish
    2016/3/11 10:00 10:40 40 对软件的使用者进行需求分析 finish
    2016/3/11 10:40 11:10 30 生成设计文档 仅为初稿,在编写过程中会根据实际情况加入新元素
    2016/3/12 13:00 15:00 120 编写程序主要模块 不停调试阶段
    2016/3/13 9:00 11:00 120 调试代码至基本功能够运行 finish
    2016/3/13 15:00 16:00 60 优化界面 使软件操作流畅
    2016/3/14 9:30 10:30 60 博文总结 finish
    2016/3/15 13:00 13:57 57 规范格式并上传博客 Markdown

    2016-3-22 1:24:32

  • 相关阅读:
    【hihocoder 1477】闰秒
    【codeforces 768F】Barrels and boxes
    【codeforces 767E】Change-free
    【codeforces 810A】Straight «A»
    【codeforces 810B】Summer sell-off
    【codeforces 810C】Do you want a date?
    【codeforces 757E】Bash Plays with Functions
    【codeforces 749D】Leaving Auction
    Java数据结构与算法(5)
    使用Xshell远程连接管理Linux实践
  • 原文地址:https://www.cnblogs.com/JINGY/p/5304520.html
Copyright © 2011-2022 走看看