废话咱们就不多讲了,直接上代码,看完的老铁记得给个收藏关注❤~。
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
using namespace std;
void showMainMenu(int left, int right);
void showExercise(int left, int right);
void createExercise(int left, int right);
void caculateAnswer(int left, int right);
void showAnswer(int left, int right);
int getRandom();
int same_judge[200];
int main() {
int choice=0;
memset(same_judge,0,sizeof(same_judge));
do {
if(choice==1)
system("cls");
int left, right;
left = getRandom();
right = left+1000;
showMainMenu(left, right);
cout << "\n\n\t\t\t\t ========是否还要继续进行操作?(1:继续 | 0:退出)========" << endl;
cin >> choice;
memset(same_judge,0,sizeof(same_judge));
} while(choice);
return 0;
}
void showMainMenu(int left, int right) {
cout << "\t\t\t\t\t\t---------口算习题----------" << endl;
cout << "\t\t\t\t\t\t| 1.生成口算题(两套) |" << endl;
cout << "\t\t\t\t\t\t| 2.显示答案 |" << endl;
cout << "\t\t\t\t\t\t| 3.退出 |" << endl;
cout << "\t\t\t\t\t\t---------------------------" << endl;
char choice;
cin >> choice;
while((choice-'0')<1 || (choice-'0')>3 || !(isdigit(choice))) {
cout << "请正确输入:" << endl;
cin >> choice;
}
switch(choice) {
case '1':
showExercise(left, right);
break;
case '2':
showAnswer(left, right);
break;
case '3':
exit(-1);
}
}
int getRandom() {
int left;
do {
srand(time(0));
left = (rand()+26314)%10000;
} while(left<=1000);
return left;
}
void showExercise(int left, int right) {
cout << "\t\t\t\t\t\t================================" << endl;
cout << "\t\t\t\t\t\t|50道100以内的混合加减运算(一)|" << endl;
cout << "\t\t\t\t\t\t================================" << endl;
createExercise(left, right);
cout << "\n\t\t\t\t\t\t================================" << endl;
cout << "\t\t\t\t\t\t|50道100以内的混合加减运算(二)|" << endl;
cout << "\t\t\t\t\t\t================================" << endl;
createExercise(left+123, right+567);
}
void createExercise(int left, int right) {
int a,b, total=1, flag=0;
for(int i=left; i<right, total<51; i++) {
srand(i);
a = rand()%100;
b = rand()/100%100;
if(a==0 || b==0)
continue;
if(flag==0)
cout << "\t\t\t\t";
flag=1;
if(same_judge[a+b]!=0)
continue;
if(a+b>100 && a>b) {
same_judge[a+b]=a-b;
printf("%2d:%2d-%2d= ",total,a,b);
if(total%5==0 && total!=50)
cout << "\n\t\t\t\t";
total++;
} else if(a+b<100) {
same_judge[a+b]=a-b;
printf("%2d:%2d+%2d= ",total,a,b);
if(total%5==0 && total!=50)
cout << "\n\t\t\t\t";
total++;
}
}
}
void showAnswer(int left, int right) {
cout << "\t\t\t\t\t\t================================" << endl;
cout << "\t\t\t\t\t\t| 第一套习题参考答案: |" << endl;
cout << "\t\t\t\t\t\t================================" << endl;
caculateAnswer(left, right);
cout << "\n\t\t\t\t\t\t================================" << endl;
cout << "\t\t\t\t\t\t| 第二套习题参考答案: |" << endl;
cout << "\t\t\t\t\t\t================================" << endl;
caculateAnswer(left+123, right+567);
}
void caculateAnswer(int left, int right) {
int a,b, total=1, flag=0;
for(int i=left; i<right, total<51; i++) {
srand(i);
a = rand()%100;
b = rand()/100%100;
if(a==0 || b==0)
continue;
if(flag==0)
cout << "\t\t\t\t";
flag=1;
if(same_judge[a+b]!=0)
continue;
if(a+b>100 && a>b) {
same_judge[a+b]=a-b;
printf("%2d:%2d-%2d=%2d ",total,a,b,a-b);
if(total%5==0 && total!=50)
cout << "\n\t\t\t\t";
total++;
} else if(a+b<100) {
same_judge[a+b]=a-b;
printf("%2d:%2d+%2d=%2d ",total,a,b,a+b);
if(total%5==0 && total!=50)
cout << "\n\t\t\t\t";
total++;
}
}
}