练习:
# include<iostream>
# include<cstdlib>
# include<ctime>
# include<synchapi.h>
# include<conio.h>
using namespace std;
int a, b, l, ll, t, qp=0;
long time_s, time_e;
string name;
int random(int x, int y){
srand(time(0)+1.299991);
int result = rand()%x+y;
return result;
}
int main(){
system("color B5");
system("title 口算小练习");
cout << "欢迎来到口算小练习!!!\n\n----------------按键继续----------------";
a = getch();
system("cls");
cout << "请输入您的名字:\n";
cin >> name;
cout << "请输入难度:\n1,10以内加减法\n2,20以内加减法\n3,100以内加减法\n\n";
cin >> a;
cout << endl;
if(a == 1)
l = 10;
else if(a == 2)
l = 20;
else
l = 100;
cout << "请输入题量:\n1,5题\n2,10题\n3,20题\n4,50题\n5,100题\n\n";
cin >> b;
cout << endl;
if(b == 1){
ll = 5;
system("color 20");
}else if(b == 2){
ll = 10;
system("color 80");
}else if(b == 3){
ll = 20;
system("color D0");
}else if(b == 4){
ll = 50;
system("color E0");
}else{
ll = 100;
system("color C0");
}
int p = random(4,1);
if(p == 1){
cout << "小提示:敲“123”可以退出哟!\n";
}else if(p == 2){
cout << "小提示:不同题量有不同背景。\n";
}else if (p == 3){
cout << "小提示:答题结束后,可以储存本次记录!\n";
}else{
cout << "小提示:可以在\'评价\'中进行评价。\n";
}
cout << "加载中......";
Sleep(2000);
system("cls");
cout << "倒计时:" << " 难度:" << a << " 题量:" << ll << endl;
for(int i=5;i>=1;i--){
cout << i << endl;
Sleep(1000);
}
cout << "开始!!!";
Sleep(200);
system("cls");
time_s = time(0);
for(int i=1;i<=ll;i++){
cout << "第" << i << "题\n";
int p = random(2,1);
if(p == 1){
int A = random(l-1,1);
int B = random(l-A,1);
cout << A << '+' << B << "=?\n";
int sb;
cin >> sb;
if(sb == A + B){
cout << name << ",答对了!\n\n";
t++;
}else if(sb == 123){
cout << name << ",真的要退出吗?还有" << ll-i+1 << "题没做呢!\n";
cout << "是,打1,不是,打2。\n";
int yesno;
cin >> yesno;
if(yesno == 2){
cout << name << ",再来一次!(现在无法使用退出代码【123】了呦!!)\n";
cin >> sb;
if(sb == A + B){
cout << name <<",答对了!\n\n";
t++;
qp++;
}else{
cout << name <<",答错了!\n\n";
qp++;
}
}else{
cout << "bye~ bye~";
Sleep(2000);
return 0;
}
}else{
cout << name << ",答错了!\n\n";
}
}else{
int A = random(l-1,2);
int B = random(A,1);
cout << A << '-' << B << "=?\n";
int sb;
cin >> sb;
if(sb == A - B){
cout << name <<",答对了!\n\n";
t++;
}else if(sb == 123){
cout << name << ",真的要退出吗?还有" << ll-i+1 << "题没做呢!\n";
cout << "是,打1,不是,打2。\n";
int yesno;
cin >> yesno;
if(yesno == 2){
cout << name << ",再来一次!(现在无法使用退出代码【123】了呦!!)\n";
cin >> sb;
if(sb == A - B){
cout << name << ",答对了!\n\n";
t++;
qp++;
}else{
cout << name << ",答错了!\n\n";
qp++;
}
}else{
cout << "bye~ bye~";
Sleep(2000);
return 0;
}
}else{
cout << name << ",答错了!\n\n";
}
}
qp++;
if((i != ll)&&(qp >= 5)){
system("cls");
qp = 0;
}
}
time_e = time(0);
cout << "----------------一键生成报告----------------";
qp = getch();
system("cls");
cout << "本次共答对" << t << "题," << "答错" << ll-t << "题," << "正确率" << 100/ll*t << "%。\n" ;
cout << "本次共用时" << time_e-time_s << "s。\n" ;
int yesno;
cout << "是否储存?\n是,打1,不是,打2。\n";
cin >> yesno;
if(yesno == 1){
char text[1010];
cout << "想要自己写一写什么吗?\n是,打1,不是,打2。\n";
cin >> yesno;
if(yesno == 1){
cout << "写一写吧(上限500字)\n";
cin >> text;
}
cout << "储存中......\n";
Sleep(1000);
cout << "储存成功 您可以在当前文件夹中找到该文件\n";
cout << "期待您的下次光临! bye~ bye~\n----------------按键退出----------------\n" ;
yesno = getch();
freopen("C:\\Users\\CZ\\Desktop\\口算小练习\\口算报告.txt", "w", stdout);
cout << "本次共答对" << t << "题," << "答错" << ll-t << "题," << "正确率" << 100/ll*t << "%。\n" ;
cout << "本次共用时" << time_e-time_s << "s。\n" ;
if(yesno == 1){
cout << text << endl;
}
cout << "(难度:" << a << " 题量:" << ll << ")\n\n";
cout << name << "de训练记录";
fclose(stdout);
}
cout << "期待您的下次光临! bye~ bye~\n----------------按键退出----------------\n" ;
yesno = getch();
}
//2.1版本 187+30行
评价:
# include<iostream>
# include<conio.h>
# include<synchapi.h>
using namespace std;
char name[110], text[10100];
int star, a;
int main(){
system("color B5");
system("title 评价");
cout << "欢迎来到\'口算小练习\'评价中心。\n----------------按键继续----------------";
a = getch();
system("cls");
cout << "请输入您的名字:\n";
cin >> name;
cout << "请输入您对\'口算小练习\'的打星(1-10):\n";
cin >> star;
cout << "请输入您对\'口算小练习\'的反馈(5000字以内):\n";
cin >> text;
system("cls");
cout << "保存中......\n";
Sleep(2000);
cout << "保存成功 谢谢您的评价!!!\n----------------按键退出----------------\n";
a = getch();
freopen("C:\\Users\\CZ\\Desktop\\口算小练习\\评价(游客勿动!!!).txt","w+",stdout);
cout << name << " de评价:" << endl;
cout << "星星值:" << star << endl;
cout << "反馈:" << endl << text;
fclose(stdout);
}
(可以自己复制)