.小学生计算机辅助系统(computer-aided instruction,cia)
前言:我知道大家不会看到后面,所以在前面写了,我是个初学者,学了有俩年了。学了几门语言却没有一门精通,c++语言复杂的语法让我始终入不了门。然后我发现了c语言,大家不要看不起这些题目。虽然他真的不难并且很无聊,但他真的很重要。我一直嫌弃课本无法传递思想,那些帖子经常把代码打出是错误的。直到我一边学一边写帖子,这真的挺难的,表述思想要一个很长的字数。我又怕太长了大家看的累,我想向大家呈现从下向上编程的考虑,对于入口出口流程控制的思考,来表达我在想啥。我会再改进,因为我也是学习无法停下来不停琢磨。大家有不对的可以在评论里打出。(ps以下代码均在小龙Dev c++实现过)
(ps怕大家找不到放前面了)
任务1:首先产生两个随机数,在1-10的乘法,在屏幕上打出题目,如6*7=?不停让学生回答直到对了为止
任务2:在一的基础上,学生回答错误,给三次机会,超过三次显示“you have tried three times test over!"程序结束
任务3:在任务一的基础上,连续做10道乘法运算,不给机会重做,,若学生回答正确,则显示“right”否则显示否则显示“wrong!10道题全部做完后,按每题10分统计并输出总分,同时为了记录学生能力提高的过程,再输出学生回答的正确率
任务 4:计算机随机产生10道四则运算题,两个操作数为1-10之间的随机数,运算类型为随机产生的加减乘除的任意一个,不给机会重做,如果学生回答正确,则显示”right!“否则显示”wrong"
任务 5:在任务4的基础上,在学生回答正确率低于75%,则重新做10道题,如果正确率低于75%,重做10道,直到回答正确率高于75%才退出程序。
任务6:开发CAI系统有解决的另一个问题是学生的疲劳问题。消除学生疲劳的一种 办法是改变人机对话界面来吸引学生注意力。在任务5的基础上,使用随机数产生一个1-4之间的随机数,配合使用switch和printf 函数调用,为学生输入的每个个正确或者错误答案输出不同的评价。
题目:
首先产生两个随机数,在1-10的乘法,在屏幕上打出题目,如6*7=?,在屏幕上显示,正确或者错误,不停让学生回答直到对了为止。
需要对输入数字进行防御性检查。对于错误的数字用getchar()函数去掉。
#include
#include
#include
main()
{
int a, b, answer;
int ret;//字符是否合法的标识,0是错误,1是对
=== int flag = 0;//是否答对的标识
srand (time(NULL));
a = rand() % 10 + 1;
b = rand() % 10 + 1;
do
{
printf("%d*%d = ?\n", a, b);
ret = scanf("%d", &answer);
while (ret != 1)
{
while (getchar() != '\n');
printf("请输入正确数字 ");
ret = scanf("%d", &answer);
}
if (answer == a * b)
{
printf("%Right!\n");
flag = 1;
}
else
{
printf("Wrong !Please try again.\n");
}
}
while (flag != 1 );
}
题目:
在任务一的基础上,学生回答错误,给三次机会,超过三次显示“you have tried three times test over!"程序结束。
//在一的基础上加上一个次数为三次的限制
#include
#include
#include
main()
{
int a, b, answer;
int ret;
int wrongTime = 0;//次数
int flag = 0;
srand (time(NULL));
a = rand() % 10 + 1;
b = rand() % 10 + 1;
do
{
printf("%d*%d = ?\n", a, b);
ret = scanf("%d", &answer);
while (ret != 1)
{
while (getchar() != '\n');
printf("input correct number ");
ret = scanf("%d", &answer);
wrongTime = wrongTime + 1;
wrongTime++;
if (wrongTime >= 3) //判断语句
break;
}
if (answer == a * b)
{
printf("%Right!\n");
flag = 1;//作对将
}
else
{
wrongTime++;
if (wrongTime < 3)
{
printf("wrong!Please try angain.\n");
}
else
{
printf("wrong! you have tried three times!Test over!");
}
}
}
while (flag != 1 && wrongTime < 3);//增加判断语句
}
题目:
在任务一的基础上,连续做10道乘法运算,不给机会重做,,若学生回答正确,则显示“right”否则显示否则显示“wrong!10道题全部做完后,按每题10分统计并输出总分,同时为了记录学生能力提高的过程,再输出学生回答的正确率
#include
#include
#include
main()
{
int a, b, answer;
int ret = 0;// 合法标识符
int rightNumber;//正确次数
srand (time(NULL));
for (int i = 0; i < 10; i++)
{
table:
a = rand() % 10 + 1;
b = rand() % 10 + 1;
printf("%d*%d = ?\n", a, b);
ret = scanf("%d", &answer);
while (ret != 1)// 判断是否合法
{
while (getchar() != '\n');
printf("input correct number\n ");
goto table;//添加的goto语句
}
if (answer == a * b) //判断是否正确
{
printf("%Right!\n");
rightNumber++;
}
else
{
printf("wrong!Please try angain.\n");
}
}
printf("Total score is %d\n", rightNumber * 10);
printf("Rate of correctness is %d%%\n", rightNumber * 10);
}
题目:
在任务三的基础上计算机随机产生10道四则运算题,(连续做10道乘法运算,不给机会重做,,若学生回答正确,则显示“right”否则显示否则显示“wrong!10道题全部做完后,按每题10分统计并输出总分,同时为了记录学生能力提高的过程,再输出学生回答的正确率)两个操作数为1-10之间的随机数,运算类型为随机产生的加减乘除的任意一个,不给机会重做,如果学生回答正确,则显示”right!“否则显示”wrong"
反思:我在做的时候,在switch的case4的语句中少了break所以只要是除法就会打出unknown operator
#include
#include
#include
main()
{
int a, b, userAnswer, systemAnswer, op, i, rightNumber;
int ret;
char opChar;
srand(time(NULL));
for (i = 0; i < 10; i++)
{
table:
a = rand() % 10 + 1;
b = rand() % 10 + 1;
op = rand() % 4 + 1;
switch (op)
{
case 1:
opChar = '+';
systemAnswer = a + b;
break;
case 2:
opChar = '-';
systemAnswer = a - b;
break;
case 3:
opChar = '*';
systemAnswer = a * b;
break;
case 4:
opChar = '/';
systemAnswer = a / b;
break;
default:
printf("Unknown operator");
}
printf("%d%c%d=?\n", a, opChar, b);
ret = scanf("%d", &userAnswer);
while (ret != 1)// 判断是否合法
{
while (getchar() != '\n');
printf("please input correct number\n ");
goto table;//添加的goto语句
}
if (userAnswer == systemAnswer)
{
printf("right!\n");
rightNumber++;
}
else
{
printf("wrong!\n");
}
}
printf("Total score is %d\n", rightNumber * 10);
printf("Rate of correctness is %d%%\n", rightNumber * 10);
return 0;
}
题目:
在任务4的基础上,在学生回答正确率低于75%,则重新做10道题,如果正确率低于75%,重做10道,直到回答正确率高于75%才退出程序。
#include
#include
#include
main()
{
int a, b, userAnswer, systemAnswer, op, i, rightNumber;
int flag;
int ret;
char opChar;
srand(time(NULL));
do
{
for (i = 0; i < 10; i++)
{
table:
a = rand() % 10 + 1;
b = rand() % 10 + 1;
op = rand() % 4 + 1;
switch (op)
{
case 1:
opChar = '+';
systemAnswer = a + b;
break;
case 2:
opChar = '-';
systemAnswer = a - b;
break;
case 3:
opChar = '*';
systemAnswer = a * b;
break;
case 4:
opChar = '/';
systemAnswer = a / b;
break;
default:
printf("Unknown operator");
}
printf("%d%c%d=?\n", a, opChar, b);
ret = scanf("%d", &userAnswer);
while (ret != 1)// 判断是否合法
{
while (getchar() != '\n');
printf("please input correct number\n ");
goto table;//添加的goto语句
}
if (userAnswer == systemAnswer)
{
printf("right!\n");
rightNumber++;
}
else
{
printf("wrong!\n");
}
}
printf("Total score is %d\n", rightNumber * 10);
printf("Rate of correctness is %d%%\n", rightNumber * 10);
if (rightNumber * 10 < 75)
{
printf("Once Again!\n");
rightNumber = 0;
flag = 1;
}
}
while (flag);
return 0;
}
题目:
开发CAI系统有解决的另一个问题是学生的疲劳问题。消除学生疲劳的一种 办法是改变人机对话界面来吸引学生注意力。在任务5的基础上,使用随机数产生一个1-4之间的随机数,配合使用switch和printf 函数调用,为学生输入的每个个正确或者错误答案输出不同的评价。
对于正确答案可以在以下有4种选择进行显示:
very good.
excellent.
Nice work .
keep up the good work .
对于错误答案可以在以下4种选择进行显示:
No.please try again.
wrong.Try once more.
Don't give up
Not correct.keep trying.
//在任务五的基础上增加防疲劳系统
//对于屏幕随机输出进行替换
#include
#include
#include
main()
{
int a, b, userAnswer, systemAnswer, op, i, rightNumber;
int flag;
int rightType, wrongType;
int ret;
char opChar;
srand(time(NULL));
do
{
for (i = 0; i < 10; i++)
{
table:
a = rand() % 10 + 1;
b = rand() % 10 + 1;
op = rand() % 4 + 1;
rightType = rand() % 4 + 1; //增加一个正确的随机数
wrongType = rand() % 4 + 1; //增加一个错误的随机数
switch (op)
{
case 1:
opChar = '+';
systemAnswer = a + b;
break;
case 2:
opChar = '-';
systemAnswer = a - b;
break;
case 3:
opChar = '*';
systemAnswer = a * b;
break;
case 4:
opChar = '/';
systemAnswer = a / b;
break;
default:
printf("Unknown operator");
}
printf("%d%c%d=?\n", a, opChar, b);
ret = scanf("%d", &userAnswer);
while (ret != 1)// 判断是否合法
{
while (getchar() != '\n');
printf("please input correct number\n ");
goto table;//添加的goto语句
}
if (userAnswer == systemAnswer)
{
switch (wrongType)
{
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!");
}
rightNumber++;
}
else
{
switch (wrongType)
{
case 1:
printf("NO.Please try again.\n");
break;
case 2:
printf("Don't give up!\n'");
break;
case 3:
printf("Keep up the good work!\n");
break;
case 4:
printf("Wrong Type!");
break;
default:
printf("wrong type");
}
}
}
printf("Total score is %d\n", rightNumber * 10);
printf("Rate of correctness is %d%%\n", rightNumber * 10);
if (rightNumber * 10 < 75)
{
printf("Once Again!\n");
rightNumber = 0;
flag = 1;
}
}
while (flag);
return 0;
}
总结:这里还有问题,就是如果输入浮点类型的数字会造成类型溢出。由于是练习其实不太严谨。
该思维导图已经全部完成,主要为思维上的连续忽略了许多细节。