• 结对作业


    项目合作者:余廷锋3118005026    罗欢3118005014

    1、githut地址:https://github.com/xiaojok/work2.git

    2、psp表格

    PSP2.1

    Personal Software Process Stages

    预估耗时(分钟)

    实际耗时(分钟)

    Planning

    计划

    30

    20

    · Estimate

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

    30

    20

    Development

    开发

    980

     710

    · Analysis

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

    50

     30

    · Design Spec

    · 生成设计文档

    30

    20

    · Design Review

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

    30

     10

    · Coding Standard

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

    100

    30

    · Design

    具体设计

    50

    100

    · Coding

    · 具体编码

    500

    450

    · Code Review

    · 代码复审

    50

    10

    · Test

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

    30

    10

    Reporting

    报告

    50

    20

    · Test Report

    · 测试报告

    10

    10

    · Size Measurement

    · 计算工作量

    10

    10

    · Postmortem & Process Improvement Plan

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

    10

    10

    合计

     980

    710

    3、设计实现过程:在设计过程中,主要是通过把每种可能的情况列出来,比如只有一个操作符的时候就把四个操作符列出来,有两个的时候就把16种情况列出来,然后再进行分类解决操作。最后设计出计算正确和错误的题数。

    4、代码:

    #include<stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <iostream>
    using namespace std;
    int numb1,numb2,numb3,i;    //随机生成的数值
    int op1,op2;    //运算符
    FILE *fp;    //指向答案文件 
    FILE *fb;    //指向题目文件 
    //辗转相除法  
    int gcd(int numb1,int numb2) {    
        if(numb2==0) return numb1;
        return    gcd(numb2,numb1%numb2);    
    }
    
    int caseone(int numb1,int numb2,int max,int i) {     
        int gcd(int numb1,int numb2);
        int temp;    //中间值
        int result;
        op1=rand()%4+1;        //op1的生成值为1到4,分别对应加法,减法,乘法,除法
        fb=fopen("Exercises.txt","a");
        fp=fopen("Answers.txt","a");    //打开文件
        switch(op1){
            case 1:        //op1为1的时候,执行加法操作
                result=numb1+numb2;
                fprintf(fp,"%d.答案=%d\n",i,result);        //写入文件
                fclose(fp);            //关闭文件
                fprintf(fb,"%d.%d+%d=%d\n",i,numb1,numb2,result);        
                fclose(fb);    
                break;
            case 2 :        //op1为2的时候,执行减法操作;
                if(numb1<numb2)        //为保证结果不为零,当出现生成的被减数比减数小,进行两者值的交换
                {
                temp=numb1;
                numb2=numb1;
                numb1=temp;
                }
                result=numb1-numb2;
                fprintf(fp,"%d.答案=%d\n",i,result);
                fclose(fp);
                fprintf(fb,"%d.%d-%d =%d\n",i,numb1,numb2,result);
                fclose(fb);
                break;
            case 3 :        //op1为3的时候,执行乘法操作;
                result=numb1*numb2;
                fprintf(fp,"%d.答案=%d\n",i,result);
                fclose(fp);
                fprintf(fb,"%d.%d*%d =%d\n",i,numb1,numb2,result);
                fclose(fb);
                break;
            case 4 :        //op1为4的时候,执行除法操作;
                if(numb2==0)
                    numb2=rand()%max+1;
                temp=gcd(numb1,numb2);
                fprintf(fp,"%d.答案=%d/%d\n",i,numb1/temp,numb2/temp);
                fclose(fp);
                fprintf(fb,"%d.%d/%d =%d/%d\n",i,numb1,numb2,numb1/temp,numb2/temp);
                fclose(fb);
                break;
            default:printf("ERROR\n");
        }
        return 0;
    }
    
    int casetwo(int numb1,int numb2,int numb3,int max,int i) {    
        int gcd(int numb1,int numb2);
        int result, result1,temp,temp1;
        op1=rand()%4+1;        
        op2=rand()%4+1;                        //op1,op2的生成值为1到4,分别对应加法,减法,乘法,除法
        fp=fopen("Answers.txt","a");
        fb=fopen("Exercises.txt","a");
        switch(op1){
            case 1 :        
                switch(op2){
                case 1 :                    //op1,op2均为加法的情况
                    result1=numb1+numb2;
                    result=result1+numb3;
                    fprintf(fp,"%d.答案=%d\n",i,result);
                    fclose(fp);
                    fprintf(fb,"%d.%d+%d+%d%=%d\n",i,numb1,numb2,numb3,result);
                    fclose(fb);
                    break;
                case 2 :                    //op1为加法,op2为减法的情况
                    result1=numb1+numb2;
                    if(result1<numb3)
                    {
                        temp=numb3;
                        numb3=numb2;
                        numb2=temp;
                    }
                    result=numb1+numb2-numb3;
                    fprintf(fp,"%d.答案=%d\n",i,result);
                    fclose(fp);
                    fprintf(fb,"%d.%d+%d-%d%=%d\n",i,numb1,numb2,numb3,result);
                    fclose(fb);
                    break;
                case 3 :                    //op1为加法,op2为乘法的情况
                    result1=numb2*numb3;
                    result=numb1+result1;
                    fprintf(fp,"%d.答案=%d\n",i,result);
                    fclose(fp);
                    fprintf(fb,"%d.%d+%d*%d%=%d\n",i,numb1,numb2,numb3,result);
                    fclose(fb);
                    break;
                case 4 :                    //op1为加法,op2为除法的情况
                    if(numb3==0)
                    {
                    numb3=rand()%max+1;
                    }
                    temp=gcd(numb2,numb3);
                    fprintf(fp,"%d.答案=%d'%d/%d\n",i,numb1,numb2/temp,numb3/temp);
                    fclose(fp);
                    fprintf(fb,"%d.%d+%d/%d%=%d'%d/%d\n",i,numb1,numb2,numb3,numb1,numb2/temp,numb3/temp);
                    fclose(fb);
                    break;
                default:printf("ERROR\n");
                }
                break;
            case 2 :        
                switch(op2){
                    case 1 :                    //op1为减法,op2为加法的情况
                        if(numb1<numb2)            //为保证结果不为零,当出现生成的被减数比减数小,进行两者值的交换
                        {
                            temp=numb1;
                            numb2=numb1;
                            numb1=temp;
                        }
                        result=numb1-numb2+numb3;
                        fprintf(fp,"%d.答案=%d\n",i,result);
                        fclose(fp);
                        fprintf(fb,"%d.%d-%d+%d%=%d\n",i,numb1,numb2,numb3,result);
                        fclose(fb);
                        break;
                    case 2 :                    //op1为减法,op2为减法的情况
                        do{
                        numb1=rand()%max;
                        numb2=rand()%max;
                        numb3=rand()%max;
                        }while((numb1-numb2-numb3)<=0);
                        result=numb1-numb2-numb3;
                        fprintf(fp,"%d.答案=%d\n",i,result);
                        fclose(fp);
                        fprintf(fb,"%d.%d-%d-%d%=%d\n",i,numb1,numb2,numb3,result);
                        fclose(fb);
                        break;
                    case 3 :                    //op1为减法,op2为乘法的情况
                        do{
                        numb1=rand()%max;
                        numb2=rand()%max;
                        numb3=rand()%max;
                        }while((numb1-numb2*numb3)<0);
                        result=numb1-numb2*numb3;
                        fprintf(fp,"%d.答案=%d\n",i,result);
                        fclose(fp);
                        fprintf(fb,"%d.%d-%d*%d%=%d\n",i,numb1,numb2,numb3,result);
                        fclose(fb);
                        break;
                    case 4 :                    //op1为减法,op2为除法的情况
                        do{
                        numb1=rand()%max;
                        numb2=rand()%max;
                        numb3=rand()%max;
                        }while((numb1-numb2/numb3)<0||numb3==0);
                        result=numb1-numb2/numb3;
                        fprintf(fp,"%d.答案=%d\n",i,result);
                        fclose(fp);
                        fprintf(fb,"%d.%d-%d/%d%=%d\n",i,numb1,numb2,numb3,result);
                        fclose(fb);
                        break;
                default:printf("ERROR\n");
                }
                break;
            case 3 :        
                switch(op2){
                    case 1 :                    //op1为乘法,op2为加法的情况
                        result=numb1*numb2+numb3;
                        fprintf(fp,"%d.答案=%d\n",i,result);
                        fclose(fp);
                        fprintf(fb,"%d.%d*%d+%d%=%d\n",i,numb1,numb2,numb3,result);
                        fclose(fb);
                        break;
                    case 2 :                    //op1为乘法,op2为减法的情况
                        do{
                        numb1=rand()%max;
                        numb2=rand()%max;
                        numb3=rand()%max;
                        }while((numb1*numb2-numb3)<0);
                        result=numb1*numb2-numb3;
                        fprintf(fp,"%d.答案=%d\n",i,result);
                        fclose(fp);
                        fprintf(fb,"%d.%d*%d-%d%=%d\n",i,numb1,numb2,numb3,result);
                        fclose(fb);
                        break;
                    case 3 :                    //op1为乘法,op2为乘法的情况
                        result=numb1*numb2*numb3;
                        fprintf(fp,"%d.答案=%d\n",i,result);
                        fclose(fp);
                        fprintf(fb,"%d.%d*%d*%d%=%d\n",i,numb1,numb2,numb3,result);
                        fclose(fb);
                        break;
                    case 4 :                    //op1为乘法,op2为除法的情况
                        do{
                        numb3=rand()%max;
                        }while(numb3==0);
                        temp1=numb1*numb2;
                        temp=gcd(temp1,numb3);
                        fprintf(fp,"%d.答案=%d/%d\n",i,temp1/temp,numb3/temp);
                        fclose(fp);
                        fprintf(fb,"%d.%d*%d/%d%=%d/%d\n",i,numb1,numb2,numb3,temp1/temp,numb3/temp);
                        fclose(fb);
                        break;
                default:printf("ERROR\n");
                }
                break;
            case 4 :        
                switch(op2){
                    case 1 :                    //op1为除法,op2为加法的情况
                        do{
                        numb2=rand()%max;
                        }while(numb2==0);
                        temp=gcd(numb1,numb2);
                        fprintf(fp,"%d.答案=%d'%d/%d\n",i,numb3,numb1/temp,numb2/temp);
                        fclose(fp);
                        fprintf(fb,"%d.%d/%d+%d%=%d'%d/%d\n",i,numb1,numb2,numb3,numb3,numb1/temp,numb2/temp);
                        fclose(fb);
                        break;
                    case 2 :                    //op1为除法,op2为减法的情况
                        do{
                        numb3=rand()%max;
                        }while(    (numb1/numb2-numb3)<0||numb2==0);
                        result=numb1/numb2-numb3;
                        fprintf(fp,"%d.答案=%d\n",i,result);
                        fclose(fp);
                        fprintf(fb,"%d.%d/%d-%d%=%d\n",i,numb1,numb2,numb3,result);
                        fclose(fb);
                        break;
                    case 3 :                    //op1为除法,op2为乘法的情况
                        do{
                        numb2=rand()%max;
                        }while(numb2==0);
                        temp1=numb1*numb3;
                        temp=gcd(temp1,numb2);
                        result=numb1/numb2*numb3;
                        fprintf(fp,"%d.答案=%d/%d\n",i,temp1/temp,numb2/temp);
                        fclose(fp);
                        fprintf(fb,"%d.%d/%d*%d%=%d/%d\n",i,numb1,numb2,numb3,temp1/temp,numb2/temp);
                        fclose(fb);
                        break;
                    case 4 :                    //op1为除法,op2为除法的情况
                        do{
                        numb2=rand()%max;
                        numb3=rand()%max;
                        }while(numb3==0||numb2==0);
                        result=numb1/numb2/numb3;
                        temp1=numb2*numb3;
                        temp=gcd(temp1,numb1);
                        fprintf(fp,"%d.答案=%d/%d\n",i,numb1/temp,temp1/temp);
                        fclose(fp);
                        fprintf(fb,"%d.%d/%d/%d%=%d/%d\n",i,numb1,numb2,numb3,numb1/temp,temp1/temp);
                        fclose(fb);
                        break;
                default:printf("ERROR\n");
                }
                break;
            default:printf("ERROR\n");
        }
        fclose(fp);
        fclose(fb);
        return 0;
    }
    
    /*计算的题目数量*/  
    int Count(char file[]) { 
        FILE *fp1;
        char a;
        int x=0;
        if((fp1=fopen(file,"r"))==NULL) {
            printf("read file failed!\n");
            exit(0);
        }
        while(!feof(fp1)) {
            a=fgetc(fp1);
            if(a=='\n') x++;
        }      
        fclose(fp1);
        return x;
    }
    /* 答案判断对错函数*/ 
    void Put_Judge(char *str1,char *str2,int n) { 
        int i,j;
        FILE *out;
        out=fopen("Grade.txt","w");
        for(i=0,j=0;i<n;i++)     /*对的个数*/ 
            if(*(str1+i)==*(str2+i))
        j++;    
        fprintf(out,"Correct:%d (",j);
        for(i=0;i<n;i++) {    /*对的序号*/  
            if(*(str1+i)==*(str2+i))
            fprintf(out," %d ",(i+1));
        }
        fprintf(out,")\n");
         fprintf(out,"Wrong:%d (",(n-j));
        for(i=0;i<n;i++) { /*错的序号*/  
            if(*(str1+i)!=*(str2+i))
            fprintf(out," %d ",(i+1));
        }
        fprintf(out,")\n");
        fclose(out);
        printf("OK");
    }
    
    /*读取学生答案的函数*/  
    void GetAnswers(char infile[],char *str) { 
        FILE *in;
        char a;
        int i=0;
        if((in=fopen(infile,"r"))==NULL) {
           printf("read file failed!\n"); 
           exit(0);
        } 
        while(!feof(in)) {
            *(str+i)=0;
            a=fgetc(in);        
            if(a!='=') 
            continue;
            while(1)
            {
                a=fgetc(in);
                if(a=='\n')break;
                *(str+i)*=10;    
                *(str+i)+=(a-48);
            }
                printf("%d ",*(str+i));
                i++;
        }
        printf("\n");
        fclose(in);
    }
    int main() {
        int subnumber,max    int opnum;
        int caseone(int numb1,int numb2,int max,int i);        //函数的声明
        int casetwo(int numb1,int numb2,int numb3,int max,int i);
        FILE *fp;
        fp=fopen("Exercises.txt","w");
        fb=fopen("Answers.txt","w");            //建立文件
        fclose(fp);
        fclose(fb);
        srand((unsigned)time(0));                //为保证每次运行程序的时候生成的题目都不一样
        printf("***************随机生成四则运算题目*****************************\n");
        printf("1.使用 -n 参数控制生成题目的个数\n");
        printf("2.使用 -r 参数控制题目中数值(自然数、真分数和真分数分母)的范围\n");
        printf("请输入n:");
        scanf("%d",&subnumber); 
        printf("请输入r:");
        scanf("%d",&max); 
        printf("题目生成中,请稍后...\n"); 
        for(i=1;i<=subnumber;i++) {        //for循环生成题目 
            opnum=rand()%2+1;
            switch(opnum) {
                case 1 :                            //当随机数是生成1个运算符时
                    numb1=rand()%max;
                    numb2=rand()%max;
                    caseone(numb1,numb2,max,i);        //执行函数的同时得同时执行把表达式输出到txt文件中
                    break;
                case 2 :            //当随机数是生成2个运算符时
                    numb1=rand()%max;
                    numb2=rand()%max;
                    numb3=rand()%max;
                    casetwo(numb1,numb2,numb3,max,i);
                    break;    
                default:printf("ERROR\n");
            }
        }
        char file1[10],file2[10],s[3]; 
        printf("校对文件答案并生成Grade.txt文件\n");
        printf("请输入练习文本:\n"); 
        scanf("%s",file1);
        printf("请输入答案文本:\n"); 
        scanf("%s",file2);
        int n;
        n=Count(file1); 
        char exe[10000]={0};
        char an[10000]={0};
        GetAnswers(file1,exe); 
        GetAnswers(file2,an);
        //Exercises.txt
        //Answers.txt
        Put_Judge(exe,an,n);
        return 0; 
    }

    5、测试运行

     

     

     

     7、项目小结

    由于没有过团队协作的经验,在这次项目中遇的了很大的困难,感觉一个人开发难度会小一点,因为不懂得如何协调好两个人的工作。通过这次项目,让我感觉到合作的重要性。

  • 相关阅读:
    System.InvalidOperationException: 找到多个与名为“Home”的控制器匹配的类型。
    MemoryStream和FileStream
    js的eval函数解析后台返回的json数据时为什加上圆括号eval("("+data+")"),而HTML页面定义的数据不用
    字符串转数组和数组转字符串
    npoi导入--从varchar数据类型到datetime数据类型转换产生一个超出范围的值问题
    IIS配置 Web部署 svg/woff/woff2字体 404错误
    委托由浅入深学习
    JavaScriptSerializer返回一条Json,页面获取值问题,数据绑定
    一文总结 CPU 基本知识
    Spring原理只要看这篇文章就够了
  • 原文地址:https://www.cnblogs.com/jmrlu/p/12701961.html
Copyright © 2020-2023  润新知