第三次作业:个人项目-小学四则运算 “软件”之初版
本次作业要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2166
我的github远程仓库的地址:https://github.com/1823406059/LJN
一、题目要求:
像《构建之法》的人物阿超那样,写一个能自动生成小学四则运算题目的命令行 “软件”。
具体要求:任何编程语言都可以,命令行程序接受一个数字输入,然后输出相应数目的四则运算题目和答案。例如输入数字是 30, 那就输出 30 道题目和答案。 运算式子必须至少有两个运算符,运算数字是在 100 之内的正整数,答案不能是负数。 如:
23 - 3 * 4 = 11
扩展要求:
1) 要求能出和真分数 (二分之一, 十二分之五,等)相关的练习题。
2) 并且要求能处理用户的输入,并判断对错,打分统计。 要求能处理用户输入的真分数, 如 1/2, 5/12 等。
初步拟定要实现的功能后,估计一下自己需要花多长时间。编程过程中记录自己实际用了多长时间。
然后和同学们比较一下各自程序的功能、实现方法的异同等等。
写博客纪录自己实现的过程和思路。
二、个人软件过程耗时估计与统计表
-
PSP模版表格如下,第3列和第4列分别对应第2列条目的估计时间和真实时间,模版表格里的时间只是示意。
| PSP2.1 | Personal Software Process Stages | Time Senior Student | Time |
| Planning | 计划 | 6 | 5 |
| · Estimate | 估计这个任务需要多少时间 | 20 | 30 |
| Development | 开发 | 30 | 20 |
| · Analysis | 需求分析 (包括学习新技术) | 5 | 6 |
| · Design Spec | 生成设计文档 | 2 | 3 |
| · Design Review | 设计复审 | 0 | 0 |
| · Coding Standard | 代码规范 | 0 | 0 |
| · Design | 具体设计 | 10 | 12 |
| · Coding | 具体编码 | 60 | 40 |
| · Code Review | 代码复审 | 0 | 20 |
| · Test | 测试(自我测试,修改代码,提交修改) | 10 | 15 |
| Reporting | 报告 | 8 | 6 |
| · | 测试报告 | 3 | 2 |
| · | 计算工作量 | 2 | 1 |
| · | 并提出过程改进计划 | 0 |
0 |
三、代码提交
提交你的源代码和可执行程序至你的github上
#include<stdio.h>
#include<math.h>
#include<time.h>
#include <stdlib.h>
void opration(void);
float numjisuan(int i,float a,float b);
char yunsuanfu(int i);
void main()
{
int i=0,n;
printf("输入运算的条数为:");
scanf("%d",&n);
do{
opration();
i++;
}while(i<n);
system("pause");
}
void opration(void)
{
float numanswer;
float x,y,z;
int a,b,c;
int j,k;
char op1,op2;
srand((unsigned)time(NULL));
do{
a=rand()%100;
b=rand()%100;
c=rand()%100;
//0,1为加减 2,3为乘除
j=rand()%4;
k=rand()%4;
if(j>1){
y=(float)a;
z=(float)b;
x=numjisuan(j,y,z);
y=x;
z=(float)c;
x=numjisuan(k,y,z);
}
else
{
if(k<2)
{
y=(float)a;
z=(float)b;
x=numjisuan(j,y,z);
y=x;
z=(float)c;
x=numjisuan(k,y,z);
}
else
{
y=(float)b;
z=(float)c;
x=numjisuan(k,y,z);
y=(float)a;
z=x;
x=numjisuan(j,y,z);
}
}
}while(x<0);
op1=yunsuanfu(j);
op2=yunsuanfu(k);
printf("%d %c %d %c %d = ",a,op1,b,op2,c);
scanf("%f",&numanswer);
if(fabs(numanswer-x)<0.01)
{
printf("答对啦!\n");
}
else
{
printf("答错啦!,正确答案是:%.1f\n",x);
}
}
float numjisuan(int i,float a,float b)
{
float x;
switch(i)
{
case 0:
x=a+b;
break;
case 1:
x=a-b;
break;
case 2:
x=a*b;
break;
case 3:
x=a/b;
break;
default:
break;
}
return x;
}
char yunsuanfu(int i)
{
char op;
switch(i)
{
case 0:
op='+';
break;
case 1:
op='-';
break;
case 2:
op='*';
break;
default:
op='/';
break;
}
return op;
}

浙公网安备 33010602011771号