基于控制台的四则运算

详细代码地址:https://git.coding.net/wangluo24/sizeyunsuan.git

1、题目要求:

写一个能自动生成小学四则运算题目的命令行 “软件”,满足以下需求:

    1. 除了整数以外,还要支持真分数的四则运算,真分数的运算,例如:1/6 + 1/8 = 7/24
    2. 运算符为 +, −, ×, ÷
    3. 并且要求能处理用户的输入,并判断对错,打分统计正确率。
    4. 要求能处理用户输入的真分数, 如 1/2, 5/12 等
    5. 使用 -n 参数控制生成题目的个数,例如执行下面命令将生成10个题目
      Myapp.exe -n 10

2、功能分析

题目要满足整数以及真分数的四则运算,整数方面相对简单,真分数要与正确答案进行对比,要用三个字母分别进行对比

实验使用C++语言进行编写

3、部分代码展示

判断用户输入与正确答案是否一致

void jiancha1(int m,int a[])
{
int q,s;

cout<<endl;
cout<<"请输入答案"<<endl;
cin>>q;

if(q==a[p])
{
r++;
cout<<"回答正确";
cout<<endl;

}
else
{
cout<<"抱歉,回答错误";
cout<<"正确答案为:"<<a[p];
cout<<endl;
}



}

void jiancha2(int m,int a[][2])
{
int z1,z3;
char z2;
cout<<endl;
cout<<"请输入答案"<<endl;
cin>>z1;
z2=cin.get();
cin>>z3;
if(z1==a[p][0]&&z2=='/'&&z3==a[p][1])
{
cout<<"回答正确";
cout<<endl;
r++;
}
else
{
cout<<"抱歉,回答错误";
cout<<"正确答案是:"<<a[p][0]<<"/"<<a[p][1]<<endl;
cout<<endl;

}
}

补充:分数部分代码

void zhenfenshu(int m, int a[][2])
{
srand(time(NULL));
for(p=0;p<m;p++)
{
int i=rand()%9+1;
int j=rand()%9+1;
while(i>=j)
{
i=rand()%9+1;
j=rand()%9+1;
}
int x=rand()%9+1;
int y=rand()%9+1;
while(x>=y)
{
x=rand()%9+1;
y=rand()%9+1;
}
int d=rand()%4;
switch(d)
{
case 0:
cout<<"("<<i<<"/"<<j<<")"<<"+"<<"("<<x<<"/"<<y<<")"<<"=";
a[p][0]=i*y+x*j;
a[p][1]=j*y;
jiancha2(m,a);
cout<<endl;
break;
case 1:
cout<<"("<<i<<"/"<<j<<")"<<"-"<<"("<<x<<"/"<<y<<")"<<"=";
a[p][0]=i*y-x*j;
a[p][1]=j*y;
jiancha2(m,a);
cout<<endl;
break;
case 2:
cout<<"("<<i<<"/"<<j<<")"<<"*"<<"("<<x<<"/"<<y<<")"<<"=";
a[p][0]=i*x;
a[p][1]=j*y;
jiancha2(m,a);
cout<<endl;
break;
case 3:
cout<<"("<<i<<"/"<<j<<")"<<"÷"<<"("<<x<<"/"<<y<<")"<<"=";
a[p][0]=i*y;
a[p][1]=j*x;
jiancha2(m,a);
cout<<endl;
break;
}


}
o=r/(float)m;
cout<<"您的正确率为:"<<100*o<<"%"<<endl;
}

PSP2.1

Personal Software Process Stages

Estimated time(min)

actual time(min)

Planning

20

20

25

· Estimate

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

200

235

Development

开发

100

120

· Analysis

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

30

35

· Design Spec

生成设计文档

15

15

· Design Review

设计复审

10

10

· Coding Standard

代码规范

5

5

· Design

具体设计

30

30

· Coding

具体编码

60

60

· Code Review

代码复审

15

15

· Test

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

20

20

Reporting

报告

15

17

·

测试报告

10

15

·

计算工作量

10

10

·

并提出过程改进计划

10

10

原文地址:https://www.cnblogs.com/wangluo24/p/6512167.html