结对编程1-模块化

  • 唐壶海201421122069
  • 林国梽201421122068

项目开发的coding.net地址:https://coding.net/u/thh514024191/p/a-simple-arithmetic-device/git

一、需求分析

  1. 有计时功能,能显示用户答完所有题目消耗的时间。
  2. 界面支持三种语言(中文简体/中文繁体/英语)用户可以选择一种语言界面

二、程序设计

  1. 计时功能设2个变量,生成题目时取系统时间,结束做题时取系统时间,二者时间差就是做题时间。
  2. 语言选择,设1个变量,取值不一样时语言就不一样。
  3. 思维导图

  4.代码展示

  

#include "stdafx.h"
#include<stdlib.h>
#include <time.h>
#include <string>
#include <iostream>

using  std::string;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int a1,a2,b1,b2,c1,c2,d,e,i,n,z,lan;
    char op1,op2;
    string s,r,w;
    string h1,h2;
    char g[] = " ";
    int right = 0;
    int wrong = 0;
    char r1[] = " ";
    char w1[] = " ";
    time_t start,stop;
    //语言选择
    cout << "language:1.简体中文2.繁体中文3.English\n";
    cin >> lan;
    //输入题数
    srand(unsigned(time(0)));
    if(lan == 1)cout << "输入题数:";
    if(lan == 2)cout << "輸入題數:";
    if(lan == 3)cout << "Number of input questions:";
    cin >> n;
    start = time(NULL);//计时开始
    //随机生成题目
    for(i=0;i<n;i++)
    {
        a1 = rand()%10;
        b1 = rand()%10;
        c1 = rand()%10;
        d = rand()%4;
        e = rand()%4;
        switch(d)
        {    
            case 0:op1='+';break;
            case 1:op1='-';break;
            case 2:op1='*';break;
            case 3:op1='/';break;
        }
        switch(e)
        {
            case 0:op2='+';break;
            case 1:op2='-';break;
            case 2:op2='*';break;
            case 3:op2='/';break;
        }
        //判断优先级
        while(op1=='/'&&b1==0)b1 = rand()%10;
        while(op2=='/'&&c1==0)c1 = rand()%10;
        if(op1=='+'&&op2=='+')z = a1 + b1 + c1;
        if(op1=='+'&&op2=='-')z = a1 + b1 - c1;
        if(op1=='+'&&op2=='*')z = a1 + (b1 * c1);
        if(op1=='+'&&op2=='/')z = a1 + (b1 / c1);
        if(op1=='-'&&op2=='+')z = a1 - b1 + c1;
        if(op1=='-'&&op2=='-')z = a1 - b1 - c1;
        if(op1=='-'&&op2=='*')z = a1 - (b1 * c1);
        if(op1=='-'&&op2=='/')z = a1 - (b1 / c1);
        if(op1=='*'&&op2=='+')z = a1 * b1 + c1;
        if(op1=='*'&&op2=='-')z = a1 * b1 - c1;
        if(op1=='*'&&op2=='*')z = a1 * b1 * c1;
        if(op1=='*'&&op2=='/')z = a1 * b1 / c1;
        if(op1=='/'&&op2=='+')z = a1 / b1 + c1;
        if(op1=='/'&&op2=='-')z = a1 / b1 - c1;
        if(op1=='/'&&op2=='*')z = a1 / b1 * c1;
        if(op1=='/'&&op2=='/')z = a1 / b1 / c1;
        cout << i+1 << "." << " ";//生成题号
        cout <<a1 << op1 << b1 << op2 << c1 << "=";
        cin >> s;//输入答案
        sprintf(g,"%d",z);
        //判断对错记录数目
        h1 += g;
        h2 += s;
        if(g == s){
            right++;
            sprintf(r1,"%d",i+1);
            r +=r1;
        }
        else{
            wrong++;
            sprintf(w1,"%d",i+1);
            w +=w1;
        }
    }
    stop = time(NULL);//计时结束
    //根据语言输出正确错误的题号和数量,还有做题所花费的时间
    if(lan == 1){
        cout << "\n正确解答:" << right << endl;
        cout << "正确题号:";
        for(i=0;i<right;i++){
            cout << r[i] << " ";
        }
        cout << "\n错误解答:" << wrong << endl;
        cout << "错误题号:";
        for(i=0;i<wrong;i++){
            cout << w[i] << " ";
        }
        cout <<endl;
        cout << "做题时间:" <<stop-start << "" << endl;
    }
    if(lan == 2){
        cout << "\n正確解答:" << right << endl;
        cout << "正確題號:";
        for(i=0;i<right;i++){
            cout << r[i] << " ";
        }
        cout << "\n錯誤解答:" << wrong << endl;
        cout << "錯誤題號:";
        for(i=0;i<wrong;i++){
            cout << w[i] << " ";
        }
        cout <<endl;
        cout << "做題時間:" <<stop-start << "" << endl;
    }
    if(lan == 3){
        cout << "\nCorrect answer:" << right << endl;
        cout << "Correct title number:";
        for(i=0;i<right;i++){
            cout << r[i] << " ";
        }
        cout << "\nError answer:" << wrong << endl;
        cout << "Wrong item number:";
        for(i=0;i<wrong;i++){
            cout << w[i] << " ";
        }
        cout <<endl;
        cout << "Use Time:" <<stop-start << "s" << endl;
    }
    system("pause");
    return 0;
}

 

三、程序运行

 1.语言选择

2.输入题数

3.答题

4.显示正确错误的题数题号和做题时间

 

四、小结感受

  个人打代码习惯了,很喜欢设a,b,c这样子的变量,但是团队之间有编码规范就不能乱命名了,后面就把新功能的变量名取的正式些。遇到考虑不全的时候,队友的意见可以省下很多思考的时间,比个人开发要轻松多了,让我深刻的体会到了1+1>2的感觉。

 五、评价队友

  • 优点:对代码的格式比较上心,有主见。
  • 缺点:有点强迫症,效率比较低。
  • 改进:多问问队友不懂的地方。

 六、PSP

 

PSPPersonal Software Process StagesTime PredictedTime
Planning 计划 10 10
Estimate 估计这个任务需要多少时间 300 200
Development 开发 250 200
Analysis 需求分析 (包括学习新技术) 10 10
Design Spec 生成设计文档 10 10
Design Review 设计复审 5 5
Coding Standard 代码规范 10 5
Design 具体设计 5 10
Coding 具体编码 200 180
Code Review 代码复审 10 8
Test 测试(自我测试,修改代码,提交修改) 10 5
Reporting 报告 60 80
  测试报告 20 30
  计算工作量 5 5
  并提出过程改进计划 8 10

 

posted @ 2017-10-22 20:13  哇哦i  阅读(155)  评论(1编辑  收藏  举报