小学生数学计算机辅助教学系统


//小学生数学计算机辅助教学系统:Computer Teaching System Of Mathematics For Primary School Students//

//头文件

#include<stdio.h>
#include<stdlib.h>      //提供srand() rand()
#include<time.h>        //提供time(NULL)

//函数声明

int questiontypes();    //问题类型 提供加法 减法 乘法 除法 四则运算 退出选项
int questionmodels();   //问题模式 类似于闯关模式 提供直到正确为止 三次机会 十道题 正确率高于百分之75
char CreateOperator(int);  //根据问题类型创建运算符
char CreateRandomOperator(); //提供四则运算模式下创建运算符
double Calculate(int,char,int); //计算运算结果
void PrintRandomRightEvaluation(); //输出正确答案评价
void PrintRandomWrongEvaluation(); //输出错误答案评价
void model_1(int);  //闯关一
void model_2(int);  //闯关二
void model_3(int);  //闯关三
void model_4(int);  //闯关四

//主函数

int main()
{
    int m,n;

    m=questiontypes();

    if(m)  //当为0的时候不做任何处理
    {
       n=questionmodels();

       switch(n)    //case一定要有break
       {
       case 1:
        model_1(m);
        break;

       case 2:
        model_2(m);
        break;

       case 3:
        model_3(m);
        break;

       case 4:
        model_4(m);
        break;
       }

    }
    else
    {

    }

    return 0;
}
int questiontypes()
{
    int p;

    printf("欢迎来到小学生数学计算机辅助教学系统!\n");

    printf("1.加法练习\n");
    printf("2.减法练习\n");
    printf("3.乘法练习\n");
    printf("4.除法练习\n");
    printf("5.四则运算练习\n");
    printf("0.退出系统\n");

    printf("请输入操作编号:\n");
    scanf("%d",&p);

    printf("\n");

    return p;
}
int questionmodels()
{
    int q;

    printf("1.闯关一,每道题做到正确为止\n");
    printf("2.闯关二,每道题有三次答题机会\n");
    printf("3.闯关三,每套题有十道题且每道题只有一次答题机会\n");
    printf("4.闯关四,每套题做到正确率大于百分之七十五为止\n");

    printf("请输入操作编号:\n");
    scanf("%d",&q);

    printf("\n");

    return q;
}
char CreateOperator(int m)
{
    char ch;

    switch(m)
    {
    case 1:
        ch='+';
        break;

    case 2:
        ch='-';
        break;

    case 3:
        ch='*';
        break;

    case 4:
        ch='/';
        break;

    case 5:
        ch=CreateRandomOperator();
        break;
    }

    return ch;
}
char CreateRandomOperator()
{
    srand(time(NULL));  //srand提供随机数种子

    char c;
    int a;

    a=rand()%4+1;       //rand是随机数生成器 rand()是[0,1)

    switch(a)
    {
    case 1:
        c='+';
        break;

    case 2:
        c='-';
        break;

    case 3:
        c='*';
        break;

    case 4:
        c='/';
        break;
    }

    return c;
}
double Calculate(int a,char c,int b) //考虑到除法运算 所以结果设置成double类型
{
    double z;

    switch(c)
    {
    case '+':
        z=a+b;
        break;

    case '-':
        z=a-b;
        break;

    case '*':
        z=a*b;
        break;

    case '/':
        z=a/b;
        break;
    }

    return z;
}
void PrintRandomRightEvaluation()
{
    srand(time(NULL));

    int a;
    a=rand()%4+1;

    switch(a)
    {
    case 1:
        printf("Very good!\n");
        break;

    case 2:
        printf("Excellent!\n");
        break;

    case 3:
        printf("Nice work!\n");
        break;

    case 4:
        printf("Keep up the good work!\n");
        break;
    }

}
void PrintRandomWrongEvaluation()
{
    srand(time(NULL));

    int a;
    a=rand()%4+1;

    switch(a)
    {
    case 1:
        printf("No. Please try again!\n");
        break;

    case 2:
        printf("Wrong. Try once more.\n");
        break;

    case 3:
        printf("Don’t give up!\n");
        break;

    case 4:
        printf("Not correct. Keep trying.\n");
        break;
    }

}
void model_1(int m)
{
    srand(time(NULL));

    int a,b;
    double c;
    char ch;
    double UserAnwser;
    int flag;

    a=rand()%100+1;
    b=rand()%100+1;
    ch=CreateOperator(m);

    c=Calculate(a,ch,b);

    printf("%d%c%d=\n",a,ch,b);

    scanf("%lf",&UserAnwser);

    do
    {
        if(UserAnwser==c)
        {
            printf("Right!\n");
            flag=1;
        }
        else
        {
            printf("Wrong!Please try again.\n");
            scanf("%lf",&UserAnwser);
            flag=0;
        }
    }while(flag==0);  //刚开始我使用的条件是UserAnwser!=c 发现非第一次输入正确答案时没有输出Right! 所以设立了flag标志变量

}
void model_2(int m)
{
    srand(time(NULL));

    int a,b;
    double c;
    char ch;
    double UserAnwser;
    int count=0;  //计数变量

    a=rand()%100+1;
    b=rand()%100+1;
    ch=CreateOperator(m);

    c=Calculate(a,ch,b);

    printf("%d%c%d=\n",a,ch,b);

    scanf("%lf",&UserAnwser);

    do
    {
        if(UserAnwser==c)
        {
            printf("Right!\n");
        }
        else
        {
            if(count==3)
            {
                printf("Wrong! You have tried three times! Test Over!\n");
                count++;
            }
            else
            {
                printf("Wrong!Please try again.\n");
                count++;
                scanf("%lf",&UserAnwser);
            }
        }
    }while(count<=3);  //给3次重做机会 不是只有3次答题机会 这里要注意文字游戏

}
void model_3(int m)
{
    srand(time(NULL));

    int a,b;
    double c;
    char ch;
    double UserAnwser;
    int i;
    int count=0; //记录答对题数 方便求总分和正确率
    int sum;

    for(i=1;i<=10;i++)
  {
    a=rand()%100+1;
    b=rand()%100+1;
    ch=CreateOperator(m);

    c=Calculate(a,ch,b);

    printf("%d%c%d=\n",a,ch,b);

    scanf("%lf",&UserAnwser);

    if(UserAnwser==c)
    {
        printf("Right!\n");
        count++;
    }
    else
    {
        printf("Wrong!\n");
    }

  }

  sum=count*10;

  printf("此次练习总分为%d 正确率为%d%%\n",sum,sum);  //这里需要注意%的输出是%%

}
void model_4(int m)
{
    srand(time(NULL));

    int a,b;
    double c;
    char ch;
    double UserAnwser;
    int i;
    int sum;
    int count;

    do
 {
    count=0; //每次count都需要清零
    sum=0;   //每次sum都需要清零

    for(i=1;i<=10;i++)
  {
    a=rand()%100+1;
    b=rand()%100+1;
    ch=CreateOperator(m);

    c=Calculate(a,ch,b);

    printf("%d%c%d=\n",a,ch,b);

    scanf("%lf",&UserAnwser);

    if(UserAnwser==c)
    {
        PrintRandomRightEvaluation();
        count++;
    }
    else
    {
        PrintRandomWrongEvaluation();
    }

  }

      sum=count*10;

      printf("此次练习总分为%d 正确率为%d%%\n",sum,sum);  //这里需要注意%的输出是%%

    }while(sum<=75);

}


测试结果:
欢迎来到小学生数学计算机辅助教学系统!
1.加法练习
2.减法练习
3.乘法练习
4.除法练习
5.四则运算练习
0.退出系统
请输入操作编号:
5

1.闯关一,每道题做到正确为止
2.闯关二,每道题有三次答题机会
3.闯关三,每套题有十道题且每道题只有一次答题机会
4.闯关四,每套题做到正确率大于百分之七十五为止
请输入操作编号:
4

65+69=
1
Not correct. Keep trying.
17/78=
1
Not correct. Keep trying.
97/75=
1
Excellent!
94-35=
1
No. Please try again!
23+95=
1
Not correct. Keep trying.
71/92=
1
Don’t give up!
52*56=
1
Don’t give up!
52*56=
1
Wrong. Try once more.
49-16=
1
Wrong. Try once more.
49-16=
1
No. Please try again!
此次练习总分为10 正确率为10%
29+12=
41
Excellent!
61-50=
11
Very good!
58+10=
68
Nice work!
35*35=
1
Not correct. Keep trying.
92/87=
1
Excellent!
89-48=
41
Very good!
98+10=
108
Nice work!
24*30=
720
Nice work!
64*62=
1
Not correct. Keep trying.
22/83=
0
Excellent!
此次练习总分为80 正确率为80%

Process returned 0 (0x0)   execution time : 83.384 s
Press any key to continue.

发布了34 篇原创文章 · 获赞 38 · 访问量 2641

猜你喜欢

转载自blog.csdn.net/qq_43779149/article/details/104403121