请编写一个能自动生成小学四则运算题目的 “软件”。
让程序能接受用户输入答案,并判定对错。
最后给出总共 对/错 的数量。
-基本需求
-显示每次测试题目数量
-用户可以选择测试类型(混合、加、减、乘、除)
-用户可以逐个题目解答
-显示答案的对错,错误的给出正确答案
-统计每次测试答对的题的个数
无
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
void jia(int a,int b);
void jian(int a,int b);
void cheng(int a,int b);
void chu(int a,int b);
int count1=0;
int main()
{
p: printf("提示:每次测试共5题,进行混合测试输入1,加法测试输入2,减法测试输入3,乘法测试输入4,除法测试输入5\n");
printf("\n");
int count=0;
int shuru;
scanf("%d",&shuru);
switch(shuru)
{
case 1:
{
int n;
int a,b;
while(true)
{
n=a%4;
srand(time(NULL));
a = rand()%100;
b = rand()%100;
if(count==5)
{
printf("本次测试共对了%d道题\n",count1);
printf("\n");
count1=0;
goto p;
}
switch(n)
{
case 0:
{
jia(a,b);
count++;
break;
}
case 1:
{
jian(a,b);
count++;
break;
}
case 2:
{
cheng(a,b);
count++;
break;
}
case 3:
{
chu(a,b);
count++;
break;
}
default:
{
count++;
break;
}
}
}
}
case 2:
{
int a,b;
while(true)
{
srand(time(NULL));
a = rand()%100;
b = rand()%100;
if(count==5)
{
printf("本次测试共对了%d道题\n",count1);
printf("\n");
count1=0;
goto p;
}
jia(a,b);
count++;
}
}
case 3:
{
int a,b;
while(true)
{
srand(time(NULL));
a = rand()%100;
b = rand()%100;
if(count==5)
{
printf("本次测试共对了%d道题\n",count1);
printf("\n");
count1=0;
goto p;
}
jian(a,b);
count++;
}
}
case 4:
{
int a,b;
while(true)
{
srand(time(NULL));
a = rand()%100;
b = rand()%100;
if(count==5)
{
printf("本次测试共对了%d道题\n",count1);
printf("\n");
count1=0;
goto p;
}
cheng(a,b);
count++;
}
}
case 5:
{
int a,b;
while(true)
{
srand(time(NULL));
a = rand()%100;
b = rand()%100;
if(count==5)
{
printf("本次测试共对了%d道题\n",count1);
printf("\n");
count1=0;
goto p;
}
chu(a,b);
count++;
}
}
default:
{
break;
}
}
//printf("本次测试共对了%d道题\n",count1);
return 0;
}
void jia(int a,int b)
{
int result;
printf("%d + %d =",a,b);
scanf("%d",&result);
if(result == a+b)
{
printf("正确!\n");
count1++;
}
else
{
printf("错误!\n正确答案是:%d\n",a+b);
}
}
void jian(int a,int b)
{
int result;
printf("%d - %d =",a,b);
scanf("%d",&result);
if(result == a-b)
{
printf("正确!\n");
count1++;
}
else
{
printf("错误!\n正确答案是:%d\n",a+b);
}
}
void cheng(int a,int b)
{
int result;
printf("%d * %d =",a,b);
scanf("%d",&result);
if(result == a*b)
{
printf("正确!\n");
count1++;
}
else
{
printf("错误!\n正确答案是:%d\n",a*b);
}
}
void chu(int a,int b)
{
float result;
float temp;
printf("%d / %d =",a,b);
if(b==0)
{
printf("出错了!\n");
return;
}
scanf("%f",&result);
temp=result*100 - ((float)a/(float)b)*100;
if(abs(temp)<0.01)
{
printf("正确!\n");
count1++;
}
else
{
printf("错误!\n正确答案是:%d\n",(float)a/(float)b);
}
}
无

(注:只截取了中间的一部分图)
对加、减、乘、除的单独测试可进行选择,也可选择混合模式,不过在写的过程中,对计算总共对的题目个数的统计不太会,之前学的有些忘了,问了下我们软件工程的老师,后来解决了问题。以及刚开始只写了混合模式的,后来改了后可以选择单独运算的模式,可以进行单向训练。不过我写的比较简单,以后还会慢慢改进的。
需求分析:1
设计:0
代码实现:15
测试:4
事后分析和总结:2
原文:http://www.cnblogs.com/tujiangfeng/p/4399804.html