组员

    李勇 201421122027

    何忠鹏 201421122024

 

代码地址:https://git.coding.net/ThinkAlone/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 \n",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 \n",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秒\n",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++图形编程的基础,时间也是不太够,还需要其它事情要做,所有没使用GUI编程。程序的基本功能在这个程序有体现,由于是控制台,有一些操作无法实现。但是这次目前主要是感受一下结对编程的乐趣,程序的缺陷比较次要吧,在这次结对编程的过程中,交流很多,学习到到也很多,还是收益很多的。图形编程QT也有接触过,只是还无法掌握。

 

评价合作伙伴

    何忠鹏同学是一个很好的合作伙伴,他对于编程兴趣很高 ,了解的知识面很广。在结对编程过程中,他能提供很多的帮助和建议,能对一个程序的实现提供很多新颖的思路。交流沟通方面也很有优势,他是我的舍友,我们能随时交流想法,这样让我们完全体验了结对编程的乐趣。

 

展示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

 
 
 
 

 

posted on 2017-10-22 18:16  ThinkAlone  阅读(275)  评论(2编辑  收藏  举报