这个作业属于哪个课程|计算机四班C语言
---😐:--😐:--😐:---|
这个作业要求在哪里|https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10269
这个作业的目标|编写出来菜单中的具体题目,并且学会运用rand()
作业正文 |观看下面内容
其他参考文献| https://blog.csdn.net/lvyibin890/article/details/80141412
2.2.2 设计思路和遇到的问题
设计思路:我是跟据上一次编写菜单的代码稍微改了一下,要用rand()来编写,我看了学长的参考内容,感觉不是很好,就自己找了一下。跟据参考内容编写,还有学长给的operation_1,集合编写。
遇到的问题:刚刚开始一年级和二年级的题目还好,就是三年级有点问题,我总是写出来和一二年级的差不多,就是办法结合起来,不是参考中给出的数据,后来经过百度和看了一下其他同学的代码,才终于成功。
2.2.3 程序结果截图
2.2.4 程序代码
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
void menu();
void help();
void error();
void operation_1(); void one_1();
void operation_2(); void two_2();
void operation_3(); void three_3();
int main()
{
int n;
printf("========== 口算生成器 ==========\n");
printf("欢迎使用口算生成器 :\n");
printf("\n");
printf("\n");
help();
while(1)
{
menu();
scanf("%d",&n);
switch(n)
{
case 1:operation_1();break;
case 2:operation_2();break;
case 3:operation_3();break;
case 4:help();break;
}
printf("\n");
if(n==5) break;
if(n>5||n<1) error();
}
return 0;
}
void help()
{
printf("帮助信息\n");
printf("您需要输入命令代号来进行操作\n");
printf("一年级题目为不超过十位的加减法\n");
printf("二年级题目为不超过百位的乘除法\n");
printf("三年级题目为不超过百位的加减乘除混合题目\n");
printf("\n");
}
void menu()
{
printf("操作列表:\n1)一年级 2)二年级 3)三年级\n");
printf("4)帮助 5)退出程序\n请输入代号:");
printf("\n");
}
void error()
{
printf("操作错误 请重新输入 ");
printf("\n");
printf("\n");
}
void operation_1()
{
printf("请输入题目数量>");
one_1();
}
void operation_2()
{
printf("请输入题目数量>");
two_2();
}
void operation_3()
{
printf("请输入题目数量>");
three_3();
}
void one_1()
{
int n,a,b,c;
scanf("%d",&n);
printf("一年级题目如下:\n");
srand((unsigned)time(NULL));
for(int i=1;i<=n;i++)
{
a=rand()%10+1;
b=rand()%10+1;
c=rand()%2;
if(c==0)
printf("%2d + %2d = ___",a,b);
else
printf("%2d - %2d = ___",a,b);
printf("\n");
}
}
void two_2()
{
int n,d,e,f;
scanf("%d",&n);
printf("二年级题目如下:\n");
srand((unsigned)time(NULL));
for(int i=1;i<=n;i++)
{
d=rand()%100;
e=rand()%100;
f=rand()%2;
if(f==0)
printf("%3d * %3d = ___",d,e);
else
printf("%3d / %3d = ___",d,e);
printf("\n");
}
}
void three_3()
{
int n,h,k,j;
scanf("%d",&n);
printf("三年级题目如下:\n");
srand((unsigned)time(NULL));
char fh[4][6] = {"*","/","+","-"};
for(int i=1;i<=n;i++)
{
h=rand()%100;
k=rand()%100;
j=rand()%4;
while (h==0||k==0||j==0)
{
h=rand() % 100;k=rand() % 100;j=rand() % 4;
}
printf("%2d %s %2d %s %2d = ___\n",h,fh[rand() % 3],k,fh[rand() % 3],j);
printf("\n");
}
}
2.2.5 Gitee上传截图与链接