标签:char* 结果 == amp .com lse srand flag print
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#define N 10
typedef struct _ti {
int a, b;
int op;
int result;
int input;
int rw;
}ti;
ti timu[N];
int fen;
int flag;
int mulu()
{
int s;
while(1) {
printf("\t\t欢迎进入二柱子快乐答题系统\n\n");
printf("1)开始出题\t\t\t\t");
printf("2)我想答题\n");
printf("3)批改试卷\t\t\t\t");
printf("4)查阅试卷\n");
printf("请做出选择:");
scanf("%d", &s);
while(getchar() != ‘\n‘);
if(s < 1 || s > 5)
printf("选择有误!请重新输入.\n");
else
break;
}
return s;
}
void chuti()
{
int i, f;
printf("确认随机出%d道题吗?(y确认):", N);
if(getchar() != ‘y‘)
return;
for(i = 0, f = 1; i < N; f ? i++ : 0) {
timu[i].a = rand() % 100+1;
timu[i].b = rand() % 100+1;
timu[i].op = rand() % 4;
if(timu[i].b == 0 && timu[i].op == 3) {
f = 0;
continue;
}
else
f = 1;
switch(timu[i].op) {
case 0: timu[i].result = timu[i].a + timu[i].b;break;
case 1: timu[i].result = timu[i].a - timu[i].b;break;
case 2: timu[i].result = timu[i].a * timu[i].b;break;
case 3: timu[i].result = timu[i].a / timu[i].b;break;
}
}
printf("出题完毕!\n");
flag = 1;
}
void kaoshi()
{
int i, f, n;
char op[] = "+-*/";
if(!flag) {
printf("还未出题!\n");
return;
}
printf("确认开始练习最后一次出的题吗?(y确认):");
if(getchar() != ‘y‘)
return;
fen = 0;
for(i = 0, f = 1; i < N; f ? ++i : 0) {
printf("题目%d: %d %c %d = ", i+1, timu[i].a, op[timu[i].op], timu[i].b);
if(!scanf("%d", &n)) {
printf("输入有误!请重试.\n");
f = 0;
} else {
timu[i].input = n;
timu[i].rw = (n == timu[i].result ? (fen += 10, 1) : 0);
f = 1;
}
}
printf("练习完毕!\n");
}
void pinfen()
{
char* a[] = {"你真棒", "好样的", "加油啊", "还需努力"};
char** p;
int n;
p = a + 3;
n = fen / 10;
if(n >= 6)p--;
if(n >= 8)p--;
if(n == 10)p--;
printf("你上次测试的总分为 %s:%d分\n", *p, fen);
}
void shijuan()
{
int i;
char op[] = "+-*/";
for(i = 0; i < N; ++i){
printf("%d %c %d = %d\t%s", timu[i].a, op[timu[i].op],
timu[i].b, timu[i].input, timu[i].rw ? "√": "×");
if(!timu[i].rw)
printf(" 正确答案: %d", timu[i].result);
putchar(‘\n‘);
}
}
int main()
{
int i;
srand(time(0));
void (*f[])() = {chuti, kaoshi, pinfen, shijuan};
while((i = mulu()) != 5) {
f[i-1]();
printf("按任意键继续...");
getch();
}
printf("欢迎下次再来练习");
return 0;
}
四:结果截图:
五:实验总结:
通过这次实验我学会了对问题进行降维,把比较难的题目分解成一个个简单的题目,这样许多难的题目就迎刃而解,给我们的工作带来很大的方便,通过这次实验我学习到了很多,希望以后的实验我能够更上一层楼。
标签:char* 结果 == amp .com lse srand flag print
原文地址:https://www.cnblogs.com/sunyangkai/p/9925729.html