|博客班级 | https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18 |
| 作业要求 | https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18/homework/11377 |
| 作业要求| <快速生成四则运算题目> |
| 学号 | <3180701320> |
二.题目要求
写一个能自动生成小学四则运算题目的程序,然后在此基础上扩展:
1)除了整数以外,还要支持真分数的四则运算,例如:1/6+1/8=7/24
2)程序要求能处理用户的输入,判断对错,累积分数
3)程序支持可以由用户自行选择加、减、乘、除运算
4)使用-n参数控制生成题目的个数,例如Myapp.exe -n 10,将生成10个题目
三.代码提交
1)提交你的源代码在你的博客上,注释好各个函数,给出相应解释,并把运行成功的界面粘贴到博客上;
2)要求逻辑清晰,界面整洁
//2015年3月6日,30道四则运算
include
include <stdio.h>
include <stdlib.h>
include <time.h>
using namespace std;
void main()
{
int A[30],B[30],i,k,t,T,a[30],b[30],c[30];
char C;
srand((unsigned)time(NULL));
t=0;T=0;
for(i = 0;i<30;i++)
{
//产生随机符号
k = rand()%4;
if(k == 0)
C = '+';
else if(k == 1)
C = '-';
else if(k == 2)
C = '';
else if(k == 3)
C = '/';
A[i] = rand()%100;
B[i] = rand()%100;
//输出题目
if(C == '+')
{cout<<A[i]<<"+"<<B[i]<<"=?"<<endl;a[i] = A[i]+B[i];}
else if(C == '-')
{cout<<A[i]<<"-"<<B[i]<<"=?"<<endl;a[i] = A[i]-B[i];}
else if(C == '')
{cout<<A[i]<<""<<B[i]<<"=?"<<endl;a[i] = A[i]B[i];}
else if(C == '/')
{cout<<A[i]<<"/"<<B[i]<<"=?"<<endl;a[i] = A[i]/B[i];}
}
//输出结果
cout<<"结果为:";
for(i=0;i<30;i++)
{
cin>>b[i];
if(a[i] == b[i])
t++;
else
{
c[T] = i;
T++;
}
}
if(t==29)
cout<<"答案正确"<<endl;
else
{
cout<<"第";
for(i=0;i<T;i++)
cout<<c[i]+1<<"答案错误"<<endl;
}
}
运行截图:
psp2.1 | 任务内容 | 计划完成需要的时间(min) | 实际完成需要的时间(min) |
---|---|---|---|
Planning | 计划 | 140 | 120 |
Estimate | 估计这个任务需要多少时间,并规划大致工作步骤 | 130 | 110 |
Development | 开发 | 120 | 110 |
Analysis | 需求分析(包括学习新技术) | 130 | 100 |
Design Spec | 生成设计文档 | 80 | 60 |
Design Review | 设计复审 | 80 | 50 |
Coding Standard | 代码规范 | 60 | 40 |
Design | 具体设计 | 130 | 80 |
Coding | 具体编码 | 240 | 200 |
Code Review | 代码复审 | 80 | 80 |
Test | 测试(自我测试,修改代码,提交修改) | 100 | 130 |
Reporting | 报告 | 50 | 80 |
Test Report | 测试报告 | 60 | 50 |
Size Measurement | 计算工作量 | 30 | 20 |
Postmortem & Process Improvement Plan | Improvement Plan 事后总结,并提出过程改进计划 | 30 | 50 |