C语言寒假大作战03

这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/CST2019-4
作业要求 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10269
这个作业的目标 使用上次作业的菜单框架,并在其基础上增加各年级题目操作函数
参考文献 百度,https://www.runoob.com/cprogramming/c-function-rand.html

1.设计思路和遇到的问题
思路:一开始在想随机数怎么生成,利用哪些函数,后面实在头大,通过百度和询问做完的同学,把思路整明白了,利用switch函数和rand函数去完成随机数的生成。
问题:看见随机数的生成这个题目我好头痛,不知从何下手,一脸懵逼。
2.程序截图


3.程序代码

#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_1();
void operation_3();void three_1();

int main()
{
	int n;
	printf("========== 口算生成器 ==========\n欢迎使用口算生成器 :\n潞水小学期中考试\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您需要输入命令代号来进行操作, 且\n");
	printf("一年级题目为十位数以内的加减法;\n二年级题目为百位数以内的乘除法;\n");
	printf("三年级题目为百位数以内的加减乘除混合题目.\n");
	printf("\n");
}
void menu()
{
	printf("操作列表:\n1)一年级    2)二年级    3)三年级\n4)帮助      5)退出程序\n请输入代号:");
}
void error()
{
	printf("宝贝,请重新输入正确数值。");
	printf("\n");
	printf("\n");
 } 
 void operation_1()
 {
 	printf("一年级题目如下:\n"); 
 	printf("\n");
 	one_1();
 }
  void operation_2()
 {
 	printf("二年级题目如下:\n"); 
 	printf("\n");
 	two_1();
 }
  void operation_3()
 {
 	printf("三年级题目如下:\n");
 	printf("\n");
 	three_1();
 }
  void one_1()
 {
    int a,b,c;
    srand((unsigned)time(NULL));
	for(int i=1;i<=10;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_1()
 {
    int a,b,c;
    srand((unsigned)time(NULL));
	for(int i=1;i<=10;i++)
	{
		a=rand()%100;
		b=rand()%100;
		c=rand()%2;
		if(c==0)
		printf("%3d * %3d = ___",a,b);
		else
		printf("%3d / %3d = ___",a,b);
	    printf("\n");
	 } 
 }
 void three_1()
 {
 	 	int a,b,c;
 	srand((unsigned)time(NULL));
 	for(int i=1;i<=10;i++)
 	{
 		a=rand()%100;
 		b=rand()%100;
 		c=rand()%4;
 		switch(c)
 		{
 			case 0:printf("%3d + %3d = ___",a,b);break;
 			case 1:printf("%3d - %3d = ___",a,b);break;
 			case 2:printf("%3d * %3d = ___",a,b);break;
 			case 3:printf("%3d / %3d = ___",a,b);break;
		 }
		printf("\n");
	 }
 }

Gitee上传截图与链接

主页链接:
https://gitee.com/you_wake_up_like_a_dream
参考资料链接:
http://c.biancheng.net/view/2043.html

posted @ 2020-02-06 15:24  你是如梦初醒  阅读(93)  评论(0编辑  收藏  举报