四则运算题目生成程序

一.作业信息

| 博客班级 | https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18 |
| ---- | ---- | ---- |
| 作业要求 | https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18/homework/11377 |
| 作业目标 | 写一个四则运算出题程序 |
| 学号 | 3180701201 |
目录

  • 一.作业信息
  • 二.作业要求
  • 三.代码提交与截图
  • 四.个人小结

二.作业要求
写一个能自动生成小学四则运算题目的程序,然后在此基础上扩展:
除了整数以外,还要支持真分数的四则运算,例如:1/6+1/8=7/24
程序要求能处理用户的输入,判断对错,累积分数
程序支持可以由用户自行选择加、减、乘、除运算
使用-n参数控制生成题目的个数,例如Myapp.exe -n 10,将生成10个题目

三.代码提交与截图

include<iostream.h>

include<stdio.h>

include<stdlib.h>

include<string.h>

include<time.h>

int A[3000];
int W[4000];
int q=0;
int v=0;
int o=0;
int measure(int x,int y)
{
int z,w;
if(x<y)
{w=x;
x=y;
y=w;}
z=y;
while(x%y!=0)
{
z=x%y;
x=y;
y=z;}
return z;
}
char Operator()
{
char op;
int i;
cin>>i;
switch(i)
{
case 1: return '+';
case 2: return '-';
case 3: return 'x';
case 4: return '/';
}
}
//整数
void integer()
{
int x,y,p,u,g,h;
char op,tp;
x=rand()%20+1;
y=rand()%20+1;
op=Operator();
if(op'-')
while(x<y)
{
x=rand()%10+1;
y=rand()%10+1;
}
cout<<x<<op<<y<<"=";
if(op
'+')
{
Q[q++]=(x+y);
W[v++]=1;
cin>>p;
if(Q[q-1]p)
o=o+10;
}
if(op
'-')
{ A[q++]=(x-y);
W[v++]=1;
cin>>p;
if(A[q-1]p)
o=o+10;
}
if(op
'x')
{
A[q++]=(xy);
W[v++]=1;
cin>>p;
if(A[q-1]p)
o=o+10;
}
if(op
'/')
{
g=measure(x,y);
A[q++]=x/g;
W[v++]=y/g;
cin>>p>>tp>>u;
h=measure(p,u);
p=p/h;u=u/h;
if((A[q-1]p)&&(W[v-1]u))
o=o+10;
}
}
//分数
void fraction()
{
int a,b,c,d,p,u,g,h;
a=rand()%20+1;
b=rand()%20+1;
c=rand()%20+1;
d=rand()%20+1;
char op,tp;
while(a<=b||c<=d)
{
a=rand()%20+1;
b=rand()%20+1;
c=rand()%20+1;
d=rand()%20+1;
}
op=Operator();
if(op=='-')
while((b
c-ad)<0)
{
a=rand()%20+1;
b=rand()%20+1;
c=rand()%20+1;
d=rand()%20+1;
}
cout<<b<<"/"<<a<<op<<d<<"/"<<c<<"=";
if(op=='+')
{ g=measure((b
c)+(ad),(ac));
A[q++]=((bc)+(ad))/g;
W[v++]=(ac)/g;
cin>>p>>tp>>u;
h=measure(p,u);
p=p/h;u=u/h;
if((A[q-1]p)&&(W[v-1]u))
o=o+10;
}
if(op=='-')
{g=measure((b
c)-(ad),(ac));
A[q++]=((bc)-(ad))/g;
W[v++]=(ac)/g;
cin>>p>>tp>>u;
h=measure(p,u);
p=p/h;u=u/h;
if((A[q-1]p)&&(W[v-1]u))
o=o+10;
}
if(op=='x')
{ g=measure(b
d,ac);
A[q++]=(b
d)/g;
W[v++]=(ac)/g;
cin>>p>>tp>>u;
h=measure(p,u);
p=p/h;u=u/h;
if((A[q-1]p)&&(W[v-1]u))
o=o+10;
}
if(op=='/')
{ g=measure(b
c,ad);
A[q++]=(b
c)/g;
W[v++]=(ad)/g;
cin>>p>>tp>>u;
h=measure(p,u);
p=p/h;u=u/h;
if((Q[q-1]p)&&(W[v-1]u))
o=o+10;
}
}
;
void main()
{
srand(time(0));
int i,n,m;
cout<< "请选择题目类型"<<endl;
cout<< "1.整数四则运算"<<endl;
cout<< "2.分数四则运算"<<endl;
cin>>i;
cout<< "请输入题的数目"<<endl;
cin>>n;
cout<< "选择运算类型"<<endl;
cout<< "1.加法"<<endl;
cout<< "2.减法"<<endl;
cout<< "3.乘法"<<endl;
cout<< "4.除法"<<endl;
for(m=1;m<=n;m++)
{
if(i==1)
{ cout<< "请输入你的选择"<<endl;
integer();
}
else
{ cout<< "请输入你的选择"<<endl;
fraction();
}
}
cout<<"题目总分为:"<<n
10<<" "<<"您的得分为:"<<o<<endl;
}

四.个人小结
1.psp表格

psp2.1 任务内容 计划完成需要的时间(min) 实际完成需要的时间(min)
Planning 计划 120 8
Development 开发 100 150
Analysis 需求分析(包括学习新技术) 8 8
Design Spec 生成设计文档 20 20
Design Review 设计复审 3 5
Coding Standard 代码规范 5 5
Design 具体设计 5 7
Coding 具体编码 40 50
Code Review 代码复审 6 8
Test 测试(自我测试,修改代码,提交修改) 10 12
Reporting 报告 6 8
Test Report 测试报告 2 2
Size Measurement 计算工作量 2 3
Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 1 3

2.心得和经验
通过本次作业,我练习了编程能力,同时也学会了Makdown编辑规范,也学会了写博客的整体流程,对博客使用更加熟练。

posted @ 2020-11-08 20:49  秋韵雨露  阅读(99)  评论(0编辑  收藏  举报