小学生教学辅助系统C语言实验报告

一、实验目的

(1)   掌握变量、函数的使用

(2)   掌握选择结构、循环结构的使用

(3)   熟悉模块化程序设计的方法

二、实验仪器或设备

微型计算机

三、总体设计(设计原理、设计方案及流程等)

设计一个简单的小学生计算机辅助教学系统,帮助小学生学习四则运算。使用模块化程序设计方法,利用函数实现各模块功能。

提示:参照第7章课后题7.14,从任务1到任务6,实现循序渐进的方式编程。

 

 

四、实验步骤(包括主要步骤、代码分析等)

五、结果分析与总结

 

#include <stdio.h>    
#include <stdlib.h>    
#include <time.h>    
int Magic(int m);
int main()
{
    int answer, answer1;
    int counter =0;
    do {

        answer = Magic(1) * Magic(2);
        printf("%d*%d=", Magic(1), Magic(2));
            

        scanf("%d", &answer1);
            if (answer == answer1) 
            {
                printf("Right!\n");
                break;
            }
            else
            {
                printf("Wrong| Please try again.\n");
            }
    } while (counter <= 1); //提示学生重做,直到答对为止
return 0;
}

int Magic(int m) //随机赋值两个1-10的数
{
    srand(time(NULL));
    int x = rand() % 10 + 1;
    int y = rand() % 10 + 1;
    if (m == 1) 
        return x;
    else if (m == 2)
        return y;
    else return -1;  
}//返回随机数

 

 

#include <stdio.h>    
#include <stdlib.h>    
#include <time.h>    
int Magic(int m);
int main()
{
    int answer, answer1;
    int counter =1;
    do {

        answer = Magic(1) * Magic(2);
        printf("%d*%d=", Magic(1), Magic(2));


        scanf("%d", &answer1);
        if (answer == answer1)
        {
            printf("Right!\n");
            break;
        }    
        
        if (counter == 3)
        {
            printf("You have three time|Test over\n");
            break;
        }
        else
        {
           printf("Wrong| Please try again.\n");
        } 
            counter++;
            
    } while (counter <=3);
    
    return 0;
}

int Magic(int m) {
    srand(time(NULL));
    int x = rand() % 10 + 1;
    int y = rand() % 10 + 1;
    if (m == 1) 
        return x;
    else if (m == 2)
        return y;
    else return -1;  
}

 

 

#include <stdio.h>    
#include <stdlib.h>    
#include <time.h>    
int Magic(int m);
int main()
{
    int answer, answer1;
    int counter = 1;
    int a=0, b=0;
    int score;
    float rate;
    do {

        answer = Magic(1) * Magic(2);
        printf("%d*%d=", Magic(1), Magic(2));


        scanf("%d", &answer1);
        if (answer == answer1)
        {
            printf("Right!\n");
            a++;
        }

        else
        {
            printf("Wrong!\n");
            b++;
        }
        counter++;

    } while (counter <= 10);
    score = a * 10;
    rate = (float)a / 10;

    printf("score=%d\n", score);
    printf("rate=%.1f%%\n", rate*100);
    return 0;
}

int Magic(int m) {
    srand(time(NULL));
    int x = rand() % 10 + 1;
    int y = rand() % 10 + 1;
    if (m == 1)
        return x;
    else if (m == 2)
        return y;
    else return -1;
}

 

 

#include <stdio.h>    
#include <stdlib.h>    
#include <time.h>    
double Magic(int m);
int main()
{
    double answer, answer1;
    int counter = 1;
    int a = 0, b = 0;
    int score, c;
    float rate;
    do {
        c = rand() % 4;
        switch (c) {
        case 0:
            answer = Magic(1) / Magic(2);
            printf("%.1f/%.1f=", Magic(1), Magic(2));
            break;
        case 1:
            answer = Magic(1) + Magic(2);
            printf("%.1f+%.1f=", Magic(1), Magic(2));
            break;
        case 2:
            answer = Magic(1) - Magic(2);
            printf("%.1f-%.1f=", Magic(1), Magic(2));
            break;
        case 3:
            answer = Magic(1) * Magic(2);
            printf("%.1f*%.1f=", Magic(1), Magic(2));
            break;

        }

        scanf("%lf", &answer1);
        if (answer == answer1)
        {
            printf("Right!\n");
            a++;
        }

        else
        {
            printf("Wrong!\n");
            b++;
        }
        counter++;

    } while (counter <= 10);
    score = a * 10;
    rate = (float)a / 10;

    printf("score=%d\n", score);
    printf("rate=%.1f%%\n", rate * 100);
    return 0;
}

double Magic(int m) {
    srand(time(NULL));
    int x = rand() % 10 + 1;
    int y = rand() % 10 + 1;
    if (m == 1)
        return x;
    else if (m == 2)
        return y;
    else return -1;
}

 

 

#include <stdio.h>    
#include <stdlib.h>    
#include <time.h>    
double Magic(int m);
int main()
{
    double answer, answer1;
    int counter = 0;
    int a = 0, b = 0;
    int score, c;
    float rate;
    do {
        counter = 0;
    
    do {
        c = rand() % 4;
        switch (c) {
        case 0:
            answer = Magic(1) / Magic(2);
            printf("%.1f/%.1f=", Magic(1), Magic(2));
            break;
        case 1:
            answer = Magic(1) + Magic(2);
            printf("%.1f+%.1f=", Magic(1), Magic(2));
            break;
        case 2:
            answer = Magic(1) - Magic(2);
            printf("%.1f-%.1f=", Magic(1), Magic(2));
            break;
        case 3:
            answer = Magic(1) * Magic(2);
            printf("%.1f*%.1f=", Magic(1), Magic(2));
            break;

        }

        scanf("%lf", &answer1);
        if (answer == answer1)
        {
            printf("Right!\n");
            a++;
        }

        else
        {
            printf("Wrong!\n");
            b++;
        }
        counter++;
        rate = (float)a / 10;
    } while (counter != 10);
    score = a * 10;


    printf("score=%d\n", score);//score表示为分数。
    printf("rate=%.1f%%\n", rate * 100);//rate表示为正确率。
    } while (rate <= 0.75);
    return 0;
}

double Magic(int m) {
    srand(time(NULL));
    int x = rand() % 10 + 1;
    int y = rand() % 10 + 1;
    if (m == 1)
        return x;
    else if (m == 2)
        return y;
    else return -1;
}

 

 

#include <stdio.h>    
#include <stdlib.h>    
#include <time.h>    
double Magic(int m);
int main()
{
    double answer, answer1;
    int counter = 1;
    int a = 0, b = 0;
    int score, c;
    float rate;
    do {
        counter = 0;

        do {
            c = rand() % 4;
            switch (c) {
            case 0:
                answer = Magic(1) / Magic(2);
                printf("%.1f/%.1f=", Magic(1), Magic(2));
                break;
            case 1:
                answer = Magic(1) + Magic(2);
                printf("%.1f+%.1f=", Magic(1), Magic(2));
                break;
            case 2:
                answer = Magic(1) - Magic(2);
                printf("%.1f-%.1f=", Magic(1), Magic(2));
                break;
            default:
                answer = Magic(1) * Magic(2);
                printf("%.1f*%.1f=", Magic(1), Magic(2));
                break;

            }

            scanf("%lf", &answer1);
            if (answer == answer1)
            {
                c = rand() % 4;
                switch (c)
                {
                case 0:
                    printf("Very good!\n");
                    break;
                case 1:
                    printf("Excellent!\n");
                    break;
                case 2:
                    printf("Nice work!\n");
                    break;
                default:
                    printf("Keep up the good work!\n");
                    break;
                }

                a++;
            }

            else
            {
                c = rand() % 4;
                switch (c)
                {
                case 0:
                    printf("No.Please try again\n");
                    break;
                case 1:
                    printf("Wrong. Try once more.\n");
                    break;
                case 2:
                    printf("Don't give up!\n");
                    break;
                default:
                    printf("Not correct. Keep trying.\n ");
                    break;

                }

                b++;
            }
            counter++;
            rate = (float)a / 10;
        } while (counter != 10);
    
        score = a * 10;


        printf("score=%d\n", score);
        printf("rate=%.1f%%\n", rate * 100);
    } while (rate <= 0.75);
    return 0;
}

double Magic(int m) {
    srand(time(NULL));
    int x = rand() % 10 + 1;
    int y = rand() % 10 + 1;
    if (m == 1)
        return x;
    else if (m == 2)
        return y;
    else return -1;
}

 

 

简短的体会分析:

写此实验我用到随机函数、do-while循环、switch语句、if语句、函数的调用。体会到使用模块化程序设计方法,利用函数实现各模块功的好处,循序渐进的方式编程有利于项目的实现。

 

posted @ 2023-12-09 22:14  ZDhr  阅读(169)  评论(0编辑  收藏  举报