fraction fraction::mul(fraction fr) {
fraction myFraction;
myFraction.above=above*fr.above; myFraction.below=below*fr.below; myFraction.reduction(); return myFraction; }
//******************分数的相除***********//
fraction fraction::div(fraction fr) {
fraction myFraction;
myFraction.above=above*fr.below; myFraction.below=below*fr.above; myFraction.reduction(); return myFraction; }
//*********************分数答案的输入判断*************//
int fraction::display(int a,int b) {
if((a==above)&&(b==below)) {
cout<<\正确\ rights=rights+1; } else {
cout<<\错误\ wrong=wrong+1; }
return rights,wrong; }
//*******************分数的赋值****************//
void fraction::setvalue(int sj1,int sj3) {
above=sj1; below=sj3; }
//*************无分数,无余数答案判断****************//
int answer(int a[],int i) { int ans;
cout<<\请输入答案:\ cin>>ans; if(ans==a[i]) {
cout<<\正确\ rights=rights+1; } else {
cout<<\错误\ wrong=wrong+1; }
return rights,wrong; }
//*************无分数,有余数答案判断****************// int answer_1(int a[],int i,int b[]) {
int ans,yushu;
cout<<\请输入商:\ cin>>ans;
cout<<\输入余数\ cin>>yushu;
if((ans==a[i])&&(yushu=b[i])) {
cout<<\正确\ rights=rights+1; } else {
cout<<\错误\ wrong=wrong+1; }
return rights,wrong; }
//*************产生带括号式子****************// void create(int maxn) {
if(!fout) //如果打开失败,outfile返回值 {
cerr << \ exit(1); }
//首先随机生成算式中操作数的个数,其数量必须大于1 int lengt;//式子长度 do{
lengt = rand()%8; }while(lengt < 2);
bool div = false; //用来防止出现除0错误 int brack_cnt = 0; //记录未匹配的左括号个数 ll num, op;
for (int i = 1; i < lengt; i++) //循环生成算式 {
if (div) //若此时需要生成的数字前的负号是'/',则需要特判此次生成的数字不能为0 {
div = false; do{
num = rand()%maxn; }while(num == 0); cout<< num; fout<< num; } else {
num= rand()%maxn; fout < }//否则直接生成数字输出 int tmpcnt = brack_cnt; for (int j = 0; j < tmpcnt; j++) //若当前有未匹配的左括号,则对每一个未匹配的左括号,都有一定概率生成相应右括号。 { if ((rand()%5) > 2) //生成右括号概率为0.6 { brack_cnt--; fout << \ cout<<\ } } op = rand()%4; //生成运算符 fout << Op[op]; cout << Op[op]; if (op == 3) //若生成了除号,则需要置相应标志位 div = true; if (!(rand()%3)) //以一定概率生成左括号,概率为1/3 { fout << \ cout<<\ brack_cnt++; num= rand()%maxn;//生成左括号后必须生成一个数字和运算符,不然可能出现(15)这样的错误 fout < if (div) //生成最后一个数字,该数字后不需要跟运算符 { div = false; do{ num = rand()%maxn; }while(num == 0); fout << num; cout<< num; } else {