zoukankan      html  css  js  c++  java
  • 结对编程-四则运算

    组员

        李勇 201421122027

        何忠鹏 201421122024

    代码地址:https://git.coding.net/hzp2018/Arithmetic02.git

    本次作业的完成内容

        本次作业基于作业一四则运算程序做增量开发,新增了如下功能

        1、良好用户界面

        2、保存历史的错题和对题的数量,用于参考。

        3、计时功能,用于计算本次练习的所花时间。

    需求分析

        在练习四则运算题目的时候,我们需要参考原来做题的正确率,来了解一下自己的实力。有时候我们做练习题不仅需要得到题目的正确率,还需要在限定时间内完成练习,这时候需要这个程序有一个计时功能,在开始练习的时候开始计时,到练习完成计算所花时间。记录题目正确率需要统计每一次的练习,这样能保证这个正确率的参考性,将数据保存到本地文本文件,使数据持久化。用户也需要良好的界面来操作程序,还需要对程序的界面进行优化。

    思维导图

    代码展示:

          

    复制代码
    int main()
    {
    
        string exp;//用于保存到TXT文件的表达式
        string str;//用于计算的表达式
        string stt;//记录表达式的计算顺序
        int cdNum;
        int ns,n,m=0;//题目的个数
        cout<<"*****************************************************"<<endl;
        cout<<"欢迎使用四则运算生成系统"<<endl;
        cout<<"*****************************************************"<<endl;
        cout<<""<<endl;
    
        srand((unsigned)time(NULL));
        ofstream location_out;
        string isrepeat;
        int range;
        string answer;
        time_t time_s;
        struct tm *date_time;
        int correntCount=0;
        int wrongCount=0;
        int totalCorrentCount=0;
        int totalWrongCount=0;
        string totalCorrentNum;
        string totalWrongNum;
        ifstream in1("CorrentCount.txt",std::ios::app);
        int sh,sm,ss;
        int eh,em,es;
        int th,tm,ts;
        int total;
    
        location_out.open("Suffix.txt", std::ios::out);
        location_out.close();
        location_out.open("Exercise.txt", std::ios::out);
        location_out.close();
        location_out.open("Answer.txt", std::ios::out);
        location_out.close();
        location_out.open("Grade.txt", std::ios::out);
        location_out.close();
        n=0;
        if(in1.eof())
        {
            location_out.open("CorrentCount.txt", std::ios::out);
            location_out <<totalCorrentCount<<endl;
            location_out<<totalWrongCount<<endl;
            location_out.close();
        }
        getline(in1,totalCorrentNum);
        getline(in1,totalWrongNum);
        totalCorrentCount=atoi(totalCorrentNum.c_str());
        totalWrongCount=atoi(totalWrongNum.c_str());
        cout<<"总错题数:"<<totalWrongCount<<"        总对题数:"<<totalCorrentCount<<endl;
        cout<<"请输入题目的数量:";
        cin>>ns;
        cout<<"请输入数值的范围:";
        cin>>range;
        time(&time_s);
        date_time = localtime(&time_s);
    
        printf("开始做题时间:%04d/%02d/%02d %02d:%02d:%02d 
    ",date_time->tm_year+1900,
               date_time->tm_mon+1,date_time->tm_mday,sh=date_time->tm_hour,
               sm=date_time->tm_min,ss=date_time->tm_sec);
        while(n<ns)
        {
            exp = "";
            cdNum = operatorNum();
            string *cd = new string[cdNum];
            string *nums = new string[cdNum + 1];
            cd = operators(cdNum);
            nums = num(cdNum,range);
    
            exp = nums[0];
            for (int i = 0; i < cdNum; i++)
            {
                exp = exp + cd[i] + nums[i + 1];
            }
            exp = insertBr(cdNum, exp);
            str=getStr(exp);
            while (exp.find("?") != string::npos)
            {
                exp.replace(exp.find("?"), 1, "÷");
            }
            str=getAns(str);
            stt=str.substr(str.find("|")+1,str.size()-1);
            isrepeat=isRepeat(stt);
            if(isrepeat.compare("no")==0)
            {
                location_out.open("Suffix.txt", std::ios::out | std::ios::app);  //以写入和在文件末尾添加的方式打开.txt文件,没有的话就创建该文件。
                location_out << n + 1 << ". ";
                location_out << stt <<endl;
                location_out.close();
                str=str.substr(0,str.find("|"));
    
                location_out.open("Answer.txt", std::ios::out | std::ios::app);  //以写入和在文件末尾添加的方式打开.txt文件,没有的话就创建该文件。
                location_out << n + 1 << ". ";
                if(str.compare("0")!=0)
                {
                    str=simplify(str);
                }
                location_out <<str<<endl;
                location_out.close();
                location_out.open("Exercise.txt", std::ios::out | std::ios::app);  //以写入和在文件末尾添加的方式打开.txt文件,没有的话就创建该文件。
                cout<<"-------------------------------------------------------------------------"<<endl;
                cout<<n+1<<". "<<exp<<"=";
                cin>>answer;
                location_out << n + 1 << ". ";
                location_out << exp << "="<<answer<<endl;
                location_out.close();
                n++;
            }
            else
            {
                m++;
                location_out.open("Grade.txt", std::ios::out | std::ios::app);  //以写入和在文件末尾添加的方式打开.txt文件,没有的话就创建该文件。
                location_out << exp << " repeat ";
                location_out << isrepeat <<endl;
                location_out.close();
            }
        }
        location_out.open("Grade.txt", std::ios::out | std::ios::app);  //以写入和在文件末尾添加的方式打开.txt文件,没有的话就创建该文件。
        location_out << "repeat: ";
        location_out << m <<endl;
        location_out.close();
        cout << "题目作答完毕"<< endl;
        correntCount=check();
        time(&time_s);
        date_time = localtime(&time_s);
        printf("做题结束时间:%04d/%02d/%02d %02d:%02d:%02d 
    ",date_time->tm_year+1900,
               date_time->tm_mon+1,date_time->tm_mday,eh=date_time->tm_hour,
               em=date_time->tm_min,es=date_time->tm_sec);
        total=(es+em*60+eh*3600)-(ss+sm*60+sh*3600);
        ts=total%60;
        tm=(total/60)%60;
        th=total/3600;
        printf("本次做题所花时间为%d小时%d分钟%d秒
    ",th,tm,ts);
        cout<<"题目检测完毕"<<endl;
        wrongCount=ns-correntCount;
        cout<<"本次错题数:"<<wrongCount<<"            本次对题数:"<<correntCount<<endl;
        totalCorrentCount+=correntCount;
        totalWrongCount+=wrongCount;
        location_out.open("CorrentCount.txt", std::ios::out);
        location_out <<totalCorrentCount<<endl;
        location_out<<totalWrongCount<<endl;
        location_out.close();
        return 0;
    }
    复制代码

    程序运行截图:

      

    小结感受

         个人认为结对编程这种模式是培养合作能力的一个很好的方式,两个人可以互相学习,交流各自的想法,求同存异,弥补自己的不足。但是由于这次作业时间不足,作业一要求用的vs2010开发,使用的是C++,之前很少接触C++的编程语法更别说用C++进行开发,基本上C++就是从零开始的。第一次次作业就做的很吃力。这次又需要在上次的基础上优化,由于没有C++图形编程的基础,时间也是不太够,还需要其它事情要做,所有没使用GUI编程。程序的基本功能在这个程序有体现,由于是控制台,有一些操作无法实现。这次课题为结对编程,所以我认为出这个题最主要的目的也是为了让我们脱离单打独斗,体会结对编程的好处,程序的缺陷比较次要吧,在这次结对编程的过程中,学会了团队合作,从对方身上也学到了很。在网上查了后用的比较多的图形化编程是QT,虽然QT也花了一些时间去了解,但是短时间内依然还无法掌握。

    评价合作伙伴

        李勇同学是睡在我上铺好几年的舍友,彼此之间比较熟悉,交流起来也比较轻松无障碍。他的编程能力也是比较强,对编程也比较有兴趣,基础知识的学习也是很扎实。在结对编程过程中,他的作业1做的比我的要更加完善,对于C++的掌握也是更好,所以比我承担了更多的代码量编写。而且他是一个比较专注的人且很有耐心的人,调试程序的时候出现各种bug不会展现出烦躁的心态。

    展示PSP

    PSP2.1 

    Personal Software Process Stages

    Time Senior Student

    Time 

    Planning

    计划

    16

    25

    · Estimate

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

    15

    22

     Development

    开发

    552

    573

     ·Analysis

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

    40

    35

    · Design Spec

    生成设计文档

    30

    25

    · Design Review

    设计复审

    15

    23

     · Coding Standard

    代码规范

    16

    15

    · Design

    具体设计

    46

    35

    · Coding

    具体编码

    264

    263

    · Code Review

    代码复审

    40

    26

     · Test

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

    40

    50

     Reporting

    报告

    63

    84

     

    测试报告

    10

    8

     

    计算工作量

    14

    13

     

    并提出过程改进计划

    15

    17

  • 相关阅读:
    什么是字典序算法?
    安装使用zookeeper
    用最快速度将0*10范围内的数进行排序
    自定义schema 流程
    dubbo原理
    jvm 线上命令
    如何实现抢红包算法?
    GC Root 对象有哪些
    Jquery动态绑定事件处理函数 bind / on / delegate
    找出数组中的最小值(es5/es6)
  • 原文地址:https://www.cnblogs.com/hezhongpeng/p/7711059.html
Copyright © 2011-2022 走看看