我有一段C语言程序,拜求哪位大神能帮我注释一下?小学生50以内,随机10道加减法的那种题

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <windows.h>
#include <time.h>
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 ;
}

/*定义字符串数组*/
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类型,不能被改变*/
const int scoreGet[4] = {0 , 5 , 7 , 10} ;
/*定义一个整形数组*/
int scoreEveryProblem[10] ;

int main() {
srand((unsigned)time(NULL)) ;//通过时间函数获得随机因子
string inputInfo ;//定义一个 字符串类型
cout << outInfo[0] ;//输出outInfo字符数组的第一行
int score = 0 ;
/*for循环并且循环10次, 1,2,3,4,5,6,7,8,9,10 */
for(int problemNumber = 1 ; problemNumber <= 10 ; problemNumber++) {
int res = rand() % 51 ;//获取一个随机数,并且其对51取余数 范围0~50
int pa = rand() % (res + 1) ;//获取一个随机数,并且对res变量+1取余数 范围不定
int pb = res - pa ;//pb等于res-pa
bool op = rand() % 2 ;//获取随机数,对2区域不是0就是1
if(op) swap(res , pa) ;//如果为1, 执行swap函数

/*循环控制错误次数3次 3,2,1*/
for(int tryTime = 3 ; tryTime >= 1 ; tryTime--) {
cout << outInfo[1] << problemNumber << outInfo[2]
<< tryTime << outInfo[3] ;//输出

cout << pa << (op ? " - " : " + ") << pb << " = " ;//通过op判断+ -法
cin >> inputInfo ;//接收输入
if(inputInfo.substr(0 , 4) == "exit") {//如果输入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 ;
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答