一、题目要求:实现一个自动生成小学四则运算题目的命令行程序
二、PSP表格
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
Planning |
计划 |
30 |
45 |
· Estimate |
· 估计这个任务需要多少时间 |
30 |
45 |
Development |
开发 |
570 |
630 |
· Analysis |
· 需求分析 (包括学习新技术) |
60 |
60 |
· Design Spec |
· 生成设计文档 |
60 |
60 |
· Design Review |
· 设计复审 (和同事审核设计文档) |
30 |
30 |
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
30 |
30 |
· Design |
· 具体设计 |
120 |
120 |
· Coding |
· 具体编码 |
180 |
240 |
· Code Review |
· 代码复审 |
60 |
60 |
· Test |
· 测试(自我测试,修改代码,提交修改) |
30 |
30 |
Reporting |
报告 |
90 |
90 |
· Test Report |
· 测试报告 |
30 |
30 |
· Size Measurement |
· 计算工作量 |
30 |
30 |
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
30 |
30 |
合计 |
|
690 |
765 |
三、需求分析
小学四则运算自动生成程序,解决的主要问题是小学老师或者学生家长给小学生出题的问题,老师和家长给学生出题时,需要很多的时间和精力。使用这个程序可以节省很多时间,并且可以自主选择题目模式,出题也可以实现多样化。
四、代码实现
- 代码可以实现的功能有,自动生成题目,定义题目类型,以及一些附加功能:给出正确答案,当减法不够减,除数为零以及无法整除的解决方法等;
代码:
#include "stdio.h"
#include"windows.h"
int right=0,wrong=0;
void add()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:%d+%d=",a,b);
scanf("%d",&c);
if(a+b!=c){printf("回答错误
");wrong++;}
else {printf("回答正确
");right++;}
}
void minu()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:%d-%d=",a,b);
scanf("%d",&c);
if(a-b!=c){printf("回答错误
");wrong++;}
else {printf("回答正确
");right++;}
}
void mul()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:%d*%d=",a,b);
scanf("%d",&c);
if(a*b!=c){printf("回答错误
");wrong++;}
else {printf("回答正确
");right++;}
}
void di()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:%d/%d=",a,b);
scanf("%d",&c);
if(a/b!=c){printf("回答错误
");wrong++;}
else {printf("回答正确
");right++;}
}
void main()
{
int choise,con=0;
printf("
欢迎光临我的C语言四则运算程序
");
system("pause");
system("cls");
while(1)
{
printf("
请选择:
加(输入1)
减(输入2)
乘(输入3)
除(输入4)
");
if(con==0)scanf("%d",&choise);
switch(choise)
{
case 1:add();break;
case 2:minu();break;
case 3:mul();break;
case 4:di();break;
}
printf("请问您想继续进行这个运算还是重新选择其他运算还是退出程序?
继续(输入1),重新(输入2),退出(输入3)");
scanf("%d",&con);
if(con==1)con=1;
if(con==2)con=0;
if(con==3)break;
}
printf("您总做了%d个题,正确%d的道,错误%d道!
",right+wrong,right,wrong);
system("pause");
}
五、 运行结果
结果: