二柱子疑难杂症3
程序:
// 二柱子在线答题.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include<iostream> #include<stdlib.h> #include<time.h> using namespace std; void boom() { float x,y; int z,t; int first_num,second_num,third_num,fourth_num; srand(time(NULL)); int n; float k; float d; float daan[100]; int zq=0; int cw=0; cout<<"需要列出多少到数学题?"<<endl; cin>>n; cout<<"********************************"<<endl; for(int i=0;i<n;i++) { z=rand()%4; first_num=rand()%10; second_num=rand()%10; third_num=rand()%10; fourth_num=rand()%10; while (second_num==0) { second_num=rand()%10; } if(first_num==0) first_num++; if(first_num==second_num) second_num++; if(first_num>second_num) { t=first_num; first_num=second_num; second_num=t; } x=(float)first_num/second_num; while (fourth_num==0) { fourth_num=rand()%10; } if(third_num==0) third_num++; if(third_num==fourth_num) fourth_num++; if(third_num>fourth_num) { t=third_num; third_num=fourth_num; fourth_num=t; } y=(float)third_num/fourth_num; z=rand()%4; switch(z) { case 0: cout<<i+1<<"、 ("<<first_num<<"/"<<second_num<<")+("<<third_num<<"/"<<fourth_num<<")=\t"<<" "; daan[i+1]=x+y; daan[i+1] = ( (float)( (int)( (daan[i+1] + 0.005) * 100 ) ) ) / 100; break; case 1: cout<<i+1<<"、 ("<<first_num<<"/"<<second_num<<")-("<<third_num<<"/"<<fourth_num<<")=\t"<<" "; daan[i+1]=x-y; daan[i+1] = ( (float)( (int)( (daan[i+1] + 0.005) * 100 ) ) ) / 100; break; case 2: cout<<i+1<<"、 ("<<first_num<<"/"<<second_num<<")*("<<third_num<<"/"<<fourth_num<<")=\t"<<" "; daan[i+1]=x*y; daan[i+1] = ( (float)( (int)( (daan[i+1] + 0.005) * 100 ) ) ) / 100; break; case 3: if(y!=0) { cout<<i+1<<"、 ("<<first_num<<"/"<<second_num<<")÷("<<third_num<<"/"<<fourth_num<<")=\t"<<" "; } else { i=i-1; } daan[i+1]=(float)x/y; daan[i+1] = ( (float)( (int)( (daan[i+1] + 0.005) * 100 ) ) ) / 100; break; if((i+1)%3==0) { for(int c=0;c<=1;c++) { cout<<endl; } } if((i+1)==n) { cout<<endl; } } for(int i=1;i<=n;i++) { cout<<"请作答,结果保留两位小数:"<<endl; cout<<i<<"、"; cin>>d; if(d==daan[i]) { cout<<"恭喜您,回答正确!"<<endl; cout<<endl; zq=zq+1; } else { cout<<"回答错误,正确答案为:"<<" "<<daan[i]<<endl; cout<<endl; cw=cw+1; } } k=(float)zq/n; cout<<"回答正确的数量为:"<<" "<<zq<<"个"<<endl; cout<<"回答错误的数量为:"<<" "<<cw<<"个"<<endl cout<<"正确率为:"<<" "<<k<<endl; } int _tmain(int argc, _TCHAR* argv[]) { boom(); int c; cout<<"要继续答题吗?(0:继续 1:退出)"<<endl; cin>>c; if(c==0) { cout<<endl; } else { cout<<endl; return 0; } return 0; }