1. 程式人生 > >個人項目:二柱子加強版

個人項目:二柱子加強版

難度 class 題目 esp stdarg std ret () cin

要求:

1.實現在線答題;

2.答題結束後,可以判斷對錯;

3.將錯的題保存起來;

#include<iostream>
#include<stdarg.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
using namespace std;
int main()
{
cout<<endl;
cout<<"歡迎來到小學生四則運算在線答題系統"<<endl;
cout<<endl;
cout<<endl;
Again:
double Q1=1; int Q01; int Q2=1; int Q3=100; char Q4=y; int Q5=1; char Q6=n; char Q7=n; double ans=0; int right=0; cout<<" 輸入題目數量:"; cin>>Q1; Q01=floor(Q1); while(1) { cout<<" 減法中需要有負數嗎?需要: 1;不需要:2"; cin>>Q7; cout<<"-------------------------------------------------------------------------
"<<endl; cout<<"開始進行答題:"<<endl; srand(time(NULL)); if(Q4==y) { while(1) { if(Q1<1) { cout<<"輸入有誤,請重新輸入題目數量:"; cin>>Q1; Q01=floor(Q1); } else { for(int j=0;j<Q01;j++) { if(j!=0&&j%Q2==0) { for(int i=0;i<Q5;i++) { cout<<endl; } } int num1=rand()%Q3; int
num2=rand()%Q3; int sign=rand()%4; switch(sign) { case 0: cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<"\t"; cin>>ans; if(ans==num1+num2) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num1+num2<<endl; } break; case 1: if(Q7==y) { cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t"; cin>>ans; if(ans==num1-num2) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num1-num2<<endl; } } else { if(num1>num2) { cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t"; cin>>ans; if(ans==num1-num2) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num1-num2<<endl; } } else { cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<"\t"; cin>>ans; if(ans==num2-num1) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num2-num1<<endl; } } } break; case 2: cout<<j+1<<":"<<" "<<num1<<"*"<<num2<<"="<<"\t"; cin>>ans; if(ans==num1*num2) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num1*num2<<endl; } break; case 3: if(num2!=0) { cout<<j+1<<":"<<" "<<num1<<"/"<<num2<<"="<<"\t"; cin>>ans; if(ans==num1/num2) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num1/num2<<endl; } } else { j--; } break; } } break; } } cout<<"共答對"<<right<<"道題;"<<"答錯"<<Q01-right<<"道題。"; break; } if(Q4==n) { while(1) { if(Q01<1) { cout<<"輸入有誤,請重新輸入題目數量:"; cin>>Q1; Q01=floor(Q1); } else { for(int j=0;j<Q01;j++) { if(j!=0&&j%Q2==0) { for(int i=0;i<=Q5;i++) { cout<<endl; } } int num1=rand()%Q3; int num2=rand()%Q3; int sign=rand()%2; switch(sign) { case 0: cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<"\t"; cin>>ans; if(ans==num1+num2) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num1+num2<<endl; } break; case 1: if(Q7==y) { cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t"; cin>>ans; if(ans==num1-num2) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num1-num2<<endl; } break; } else { if(num1>num2) { cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t"; cin>>ans; if(ans==num1-num2) { cout<<"正確"<<endl; right++; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num1-num2<<endl; } break; } else { cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<"\t"; cin>>ans; if(ans==num2-num1) { cout<<"正確"; } else { cout<<"答錯了!"<<endl; cout<<"正確答案是:"<<num2-num1<<endl; } break; } } break; } } } break; } cout<<"共答對"<<right<<"道題;"<<"答錯"<<Q01-right<<"道題。"<<endl; break; } else { cout<<"輸入有誤,請按要求輸入!"<<endl; } } cout<<endl; while(1) { cout<<"是否繼續?(y:繼續;n:退出)"; cin>>Q6; if(Q6==y) { goto Again; } if(Q6==n) { goto Exit; } else { cout<<"輸入有誤,請重新輸入:"; } } Exit: return 0; }

技術分享圖片

個人總結:這次編程難度較大,主要學習到了if語句的多重利用,如何記錄錯題,確實想不到有效的解決方法。

個人項目:二柱子加強版