V2.0 of primary School students ' computer Aided teaching system
Develop a computer assisted instruction system for primary school students. Using a random book generation function to produce random numbers between 1~10 as operands, a arithmetic problem is randomly generated, and the switch statement and print () function calls are used to output different evaluations of the correct or incorrect answers entered by the student. If the correct rate is less than 75% after the 10 questions are completed, 10 questions will be returned until the correct rate is higher than 75% before exiting the program. A modular programming method is required.
#include <stdio.h> #include <stdlib.h> #include <time.h> int Calculate (int x,char op,int y);/* Declare function calculate (), compute (x,y) Arithmetic (by op)/int createrandomnumber (); /* Declare Function Createrandomnumber (), generate a random integer of 1-10 */char createrandomoperator (); /* Declare Function createrandomoperator (), randomly generate an operation symbol (+ 、-、 *,/)/void Printrandomrightevaluation (); /* Declaration function Printrandomrightevaluation (), generate a topic to do the right random hint/void printrandomwrongevaluation ();
/* Declare Function printrandomwrongevaluation (), generate a random hint of a problem doing wrong/int main () {int a,b,useranswer,i,rightnumber=0,flag=0; /*a,b random Integer, Useranswer is the user answer, I is the control loop variable, Rightnumber is the correct answer number, flag marks, when the score <75 points, its value is 1*/char Opchar; /*opchar is the operator/Srand (Time (NULL));
/*time (NULL) return value as the seed that generates random numbers/do{for (i=0;i<10;i++)/* Loop 10 times, do 10 questions/{ A=createrandomnumber (); /* Generate a random number assignment to the integer variable a*/b=createrandomnumber ();
/* Generate a random number assignment to the integer variable b*/ Opchar=createrandomoperator (); /* Generates a random operator assignment to the character variable opchar*/printf ("%d%c%d=?\n", a,opchar,b); /* Output of a arithmetic expression =. * * SCANF ("%d", &useranswer); /* User Input answer */if (useranswer==calculate (A,OPCHAR,B))/* If the answer is correct/{Printrandomrightevalu Ation (); /* Output a topic to do the random hint * * * rightnumber++; /* Answer the correct question number plus 1*/} else/* If the answer is not correct * * Prin Trandomwrongevaluation ();
/* Output a problem to do the wrong random Prompt/} printf ("Total score is%d\n", rightnumber*10);
printf ("Rate of correctness is%d%%\n", rightnumber*10);
if (rightnumber*10<75) * * If the score is less than 75 points * * printf ("Once again!\n"); rightnumber=0;
/* Correct answer number 0 * * flag=1;
}}while (flag);
return 0; }/* Function: The arithmetic (operator determined by the OP) that computes two numbers (x,y). ), returns the calculated result value of */int Calculate (iNT X,char op,int y) {switch (OP) {case ' + ': return x+y;
Case '-': return x-y;
Case ' * ': return x*y;
Case '/': return x/y;
default:printf ("Operator error!\n"); return 0; }/* Function function: Generate a random integer of 1-10/int createrandomnumber () {return rand ()%10+1}/* Function function: Randomly generate an operator symbol (+,-,*,/)/char Createra
Ndomoperator () {int op;
Op=rand ()%4+1;
Switch (OP) {case 1:return ' + ';
Case 2:return '-';
Case 3:return ' * ';
Case 4:return '/';
return 0;
/* Function function: Generate a topic to do the right random hint/void printrandomrightevaluation () {int i;
I=rand ()%4+1;
switch (i) {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
default:printf ("wrong type!");
}//* Function function: Generate a random hint of a problem doing wrong/void printrandomwrongevaluation () {int i; I=rand ()%4+1;
switch (i) {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
default:printf ("wrong type!"); }
}