结对编程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计划1010
Estimate估计这个任务需要多少时间300200
Development开发250200
Analysis需求分析 (包括学习新技术)1010
Design Spec生成设计文档1010
Design Review设计复审55
Coding Standard代码规范105
Design具体设计510
Coding具体编码200180
Code Review代码复审108
Test测试(自我测试,修改代码,提交修改)105
Reporting报告6080
 测试报告2030
 计算工作量55
 并提出过程改进计划810

 

转载于:https://www.cnblogs.com/thh514024191/p/7711416.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值