小学生测验 2. 课题说明:向小学1~2年级学生,随机选择两个整数和加减法形成算式要求学生作答。

2024-11-25 03:20:56
推荐回答(3个)
回答1:

//原创代码,欢迎参考,编译环境:devcpp 4.9.9.2
//添加了一些头文件,楼主可以再编译试试
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std ;

const string outInfo[13] = {
"欢迎使用上机评测系统,请依提示操作,要退出系统,请输入\"exit\"\n\n" ,
"当前是第 " ,
" 题,您还有 " ,
" 次机会:\n" ,
"您已经选择退出,您的当前得分是: " ,
"\n系统即将退出,请再接再厉..." ,
"恭喜您回答正确,请继续回答下一题..\n\n" ,
"您的回答错误,请继续尝试..\n\n" ,
"您第 " ,
" 题的得分是 : " ,
" 。\n" ,
"您的总得分是 : " ,
" 。\n\n"
} ;
const string resultInfo[5] = {
"TRY AGAIN\n" ,
"PASS\n" ,
"OK\n" ,
"GOOD\n" ,
"SMART\n"
} ;
const int scoreGet[4] = {0 , 5 , 7 , 10} ;
int scoreEveryProblem[10] ;

int main() {
srand((unsigned)time(NULL)) ;
string inputInfo ;
cout << outInfo[0] ;
int score = 0 ;
for(int problemNumber = 1 ; problemNumber <= 10 ; problemNumber++) {
int res = rand() % 51 ;
int pa = rand() % (res + 1) ;
int pb = res - pa ;
bool op = rand() % 2 ;
if(op) swap(res , pa) ;

for(int tryTime = 3 ; tryTime >= 1 ; tryTime--) {
cout << outInfo[1] << problemNumber << outInfo[2]
<< tryTime << outInfo[3] ;

cout << pa << (op ? " - " : " + ") << pb << " = " ;
cin >> inputInfo ;
if(inputInfo.substr(0 , 4) == "exit") {
system("cls") ;
cout << outInfo[4] << score << outInfo[5] ;
for(int t = 0 ; t < 1000000000 ; t++) ;
return 0 ;
}
else {
int ans ;
sscanf(inputInfo.c_str() , "%d" , &ans) ;
if(ans == res) {
cout << outInfo[6] ;
score += scoreGet[tryTime] ;
scoreEveryProblem[problemNumber - 1] = scoreGet[tryTime] ;
break ;
}
else if(tryTime > 1) {
cout << outInfo[7] ;
}
else {
cout << pa << (op ? " - " : " + ") << pb << " = " << res << "\n\n" ;
}
}
}
}
for(int i = 0 ; i < 10 ; i++) {
cout << outInfo[8] << (i + 1) << outInfo[9]
<< scoreEveryProblem[i] << outInfo[10] ;
}
cout << outInfo[11] << score << outInfo[12] ;
cout << resultInfo[min(4 , max(0 , (score - 50) / 10))] << endl ;
system("pause") ;
return 0 ;
}

回答2:

已经下班了,暂时实现加法,减法自已实现吧!

#include
#include
#include

struct myadd{ int a; int b; };

bool randadd(myadd &theadd)
{
int a,b;
srand((unsigned int)time(NULL));
a=rand()%50;
b=rand()%50;
if (a+b<50)
{
theadd.a=a;
theadd.b=b;
return true;
}
else
return false;
}
void main()
{
int c;
int i=1,tm=0,sum=0;
myadd theadd1;

while(tm<10)
{
printf("当前为第%d题,让我想想考你什么呢?\n",tm+1);
while(!randadd(theadd1))
{

}
i=1;
while(i%4)
{
printf("%d + %d =",theadd1.a,theadd1.b);
scanf("%d",&c);
if(theadd1.a+theadd1.b==c)
{
sum+=1;
printf("答对了,加10分!\n");
break;
}
else
printf("很遗憾,答错了,继续努力!\n");
i+=1;
}
tm+=1;
}
switch(sum)
{
case 10:
case 9:
printf("smart");
break;
case 8:
printf("GOOD");
break;
case 7:
printf("OK");
break;
case 6:
printf("PASS");
break;
default:
printf("TRY AGAIN");
}
printf("你的总得分为:%d\n",sum*10);
}

回答3:

13+26=
20+13=
10+16=
45+3=
12+13=
15+6=
13+9=
25+22=
36+9=
12+7=