算式線上答題
阿新 • • 發佈:2018-11-07
設計思路:隨機兩個兩位數,再隨機產生一個+-*/符號,連線兩個數。將正確答案存和答案比較,用來判斷正誤。
程式碼:
1 #include<iostream.h> 2 #include<stdlib.h> 3 #include<time.h> 4 void boom() 5 { 6 float x,y; 7 int a,b; 8 int first_num,second_num; 9 srand(time(NULL)); 10 int n; 11 float k; 12 float d; 13 float daan[100]; 14 intzq=0; 15 int cw=0; 16 cout<<"輸入題目數量:"<<endl; 17 cin>>n; 18 for(int i=0;i<n;i++) 19 { 20 21 a=rand()%4; 22 first_num=rand()%100; 23 second_num=rand()%100; 24 a=rand()%4; 25 switch(a) 26 { 27 case 0: 28 cout<<i+1<<"、 "<<first_num<<"+"<<second_num<<"="<<" "; 29 daan[i+1]=first_num+second_num; 30 break; 31 case 1: 32 cout<<i+1<<"、 "<<first_num<<"*"<<second_num<<"="<<" "; 33 daan[i+1]=first_num*second_num; 34 break; 35 case 2: 36 if(first_num>second_num) 37 {cout<<i+1<<"、 "<<first_num<<"-"<<second_num<<"="<<" "; 38 daan[i+1]=first_num-second_num; 39 } 40 else{ 41 i=i-1; 42 } 43 daan[i+1]=first_num-second_num; 44 break; 45 case 3: 46 47 if(y!=0&&first_num>second_num&&first_num%second_num==0) 48 { 49 cout<<i+1<<"、 "<<first_num<<"/"<<second_num<<"="<<" "; 50 } 51 else 52 { 53 i=i-1; 54 } 55 daan[i+1]=first_num/second_num; 56 break; 57 } 58 if((i+1)%3==0) 59 { 60 for(int c=0;c<=1;c++) 61 { 62 cout<<endl; 63 } 64 } 65 if((i+1)==n) 66 { 67 cout<<endl; 68 } 69 } 70 for(i=1;i<=n;i++) 71 { 72 cout<<"請答題:"<<endl; 73 cout<<i<<"、"; 74 cin>>d; 75 if(d==daan[i]) 76 { 77 cout<<"回答正確!"<<endl; 78 cout<<endl; 79 zq=zq+1; 80 } 81 else 82 { 83 cout<<"回答錯誤,正確答案為:"<<" "<<daan[i]<<endl; 84 cout<<endl; 85 cw=cw+1; 86 } 87 } 88 k=(float)zq/n; 89 cout<<"答對數為:"<<" "<<zq<<"個"<<endl; 90 cout<<"答錯數為:"<<" "<<cw<<"個"<<endl; 91 cout<<"正確率為:"<<" "<<k<<endl; 92 } 93 int main() 94 { 95 boom(); 96 main(); 97 return 0; 98 }
專案計劃總結:
執行截圖
團隊皁片: