这个作业属于哪个课程 | https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19 |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/homework/11376 |
这个作业的目标 | 写一个能自动生成小学四则运算题目的程序 |
学号 | 3190704224 |
写一个能自动生成小学四则运算题目的程序,然后在此基础上扩展:
1)除了整数以外,还要支持真分数的四则运算,例如:1/6+1/8=7/24
2)程序要求能处理用户的输入,判断对错,累积分数
3)程序支持可以由用户自行选择加、减、乘、除运算
4)使用-n参数控制生成题目的个数,例如Myapp.exe -n 10,将生成10个题目
`#include<stdio.h>
include<math.h>
include<windows.h>
int right = 0;
int wrong = 0;
void add()//分数加法
{
int a, b, c, d, e;
float f, m, n,g;
a = rand() % 100;
b = rand() % 100+1;
c = rand() % 100;
d = rand() % 100+1;
printf("请回答:\n\t\t %d/%d + %d/%d = ", a, b,c,d);
scanf("%d", &g);
m = ad + cb;
n = bd;
printf("%d/%d", m, n);
f = m / n;
if (fabs(f-g)<1e-7)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void minu()//分数减法
{
int a, b, c, d, e;
float f, m, n,g;
a = rand() % 100;
b = rand() % 100 + 1;
c = rand() % 100;
d = rand() % 100 + 1;
printf("请回答:\n\t\t %d/%d - %d/%d = ", a, b,c,d);
scanf("%d", &g);
m = ad - cb;
n = bd;
printf("%d/%d", m, n);
f = m / n;
if (fabs(f - g)<1e-7)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void mul()//分数乘法
{
int a, b, c, d, e;
float f, m, n, g;
a = rand() % 100;
b = rand() % 100 + 1;
c = rand() % 100;
d = rand() % 100 + 1;
printf("请回答:\n\t\t %d/%d * %d/%d = ", a, b,c,d);
scanf("%d", &g);
m = ac;
n = bd;
printf("%d/%d", m, n);
f = m / n;
if (fabs(f - g)<1e-7)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void di()//分数除法
{
int a, b, c, d, e;
int divisor;
float f, m, n, g;
a = rand() % 100;
b = rand() % 100 + 1;
c = rand() % 100;
d = rand() % 100 + 1;
printf("请回答:\n\t\t %d/%d / %d/%d = ", a, b,c,d);
scanf("%d", &g);
m = ad;
n = bc;
printf("%d/%d", m, n);
f = m / n;
if (fabs(f - g)<1e-7)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void main()//主函数
{
int choise;
int con = 0;
int x;
int n = 0;
printf("\n\t\t\t四则运算\n\n");
while (1)
{
printf("请选择:\n");
printf("\t\t\t 加法运算(请输入1)\n");
printf("\t\t\t 减法运算(请输入2)\n");
printf("\t\t\t 乘法运算(请输入3)\n");
printf("\t\t\t 除法运算(请输入4)\n");
printf("\t\t\t 退出运算(请输入5)\n");
scanf("%d", &choise);
switch (choise)
{
case 1:
add();
break;
case 2:
minu();
break;
case 3:
mul();
break;
case 4:
di();
break;
case 5:
return;
}
}
printf("您总共完成了 %d 道题\n正确 %d 道\n错误 %d 道\n", right + wrong, right, wrong);
}`
好多东西都忘记了,最后的调试一直弄不出来,时间比较紧,就实现了部分功能,后期会自己完善的。