C语言课程设计:小学生考试系统

题目描述

利用C语言编写一个小学生考试系统,能够实现加减乘除随机题目生成,以及从文件中加载题目。学生答完题目后,程序能够进行对错判断以及正确率计算。

源代码

#include 
#include 
#include 

//定义习题结构
struct test{
    char text;
    char texts[50];
    int b; //第一个数字
    int c; //第二个数字
    int result;
}sql[10];

//选择习题模式
int  selectPra()
{
    int kind;
    printf("请选择题库:\n");
    printf("----------------\n");
    printf("1.系统自动生成\n");
    printf("2.来自文件\n");
    printf("----------------\n");
    scanf("%d",&kind);
    while(kind!=1&&kind!=2)
    {
        printf("选择错误,请重新选择:");
        scanf("%d",&kind);
    }
    if(kind==1)
    {
        makePra();
    }

    else if(kind==2)
    {
        readPra();
    }
    return 0;
}
//随机生成习题
int makePra()
{
    int a,b,c;// b、c为计算变量
    srand(time(0));
    int i=0;
    for(i=0;i<10;i++)
    {
        a = rand();
        //加法
       if(a%4==0)
        {
            b = rand()%100;
            c = rand()%100;
            while(b+c>100)
            {
                c-=9;
            }
            sql[i].text = '+';
            sql[i].b = b;
            sql[i].c = c;
            sql[i].result = b+c;
        }
       //除法
        else if(a%4==1)
        {
            b = rand()%9+1;
            c = rand()%9+1;
            sql[i].result = c;
            sql[i].b = b*c;
            sql[i].c = b;
            sql[i].text = '/';
        }
        //减法
        else if(a%4==2)
        {
            b = rand()%100;
            c = rand()%100;
            while(b
运行结果

C语言课程设计:小学生考试系统_第1张图片

你可能感兴趣的:(C语言课程设计:小学生考试系统)