#include <iostream>using namespacestd; #include<stdlib.h>#include<time.h>intMain () {inta,b,ans,res,c1=0, c2=0, c3=0, c4=0, T,i,n;intp; srand ((unsigned) time (NULL)); while(1) {cout<<"\n--pupils arithmetic exercises--\n"; cout<<"--1. Addition Operation--\n"; cout<<"--2. Subtraction Operation--\n"; cout<<"--3. Multiplication Operation--\n"; cout<<"--4. Division Operation--\n"; cout<<"--5. Quit Practice--\n"; cout<<"--Please enter the digital 1-5:--\n"; CIN>>p; Switch(p) { Case 1: cout<<"--Please do the addition operation--\n"; cout<<"--Please enter the number of questions--\n"; CIN>>N; for(i=1; i<=n;i++) {a=rand ()% About+1;//rand ()%a results in a maximum of a-1*B=rand ()% About+1; Res=a+b; cout<<a<<"+"<<b<<"="; CIN>>ans; if(ans==Res) {cout<<"you got the right answer,!\n."; C1++; } Else{cout<<"You got the wrong answer,!\n."; cout<<"the correct answer is:"<<res<<Endl; } } Break; Case 2: cout<<"--Please perform the subtraction operation--\n"; cout<<"--Please enter the number of questions--\n"; CIN>>N; for(i=1; i<=n;i++) {a=rand ()% About+1; b=rand ()% About+1; if(a<b) {T=a;a=b;b=T; } Res=a-b; cout<<a<<"-"<<b<<"="; CIN>>ans; if(ans==Res) {cout<<"you got the right answer,!\n."; C2++; } Else{cout<<"you answered the wrong question!"<<Endl; cout<<"the correct answer is:"<<res<<Endl; } } Break; Case 3: cout<<"--Please multiply the operation--\n"; cout<<"--Please enter the number of questions--\n"; CIN>>N; for(i=1; i<=n;i++) {a=rand ()% About+1; b=rand ()% About+1; Res=a*b; cout<<a<<"*"<<b<<"="; CIN>>ans; if(ans==Res) {cout<<"you got the right answer,!\n."; C3++; } Else{cout<<"you answered the wrong question!"<<Endl; cout<<"the correct answer is:"<<res<<Endl; } } Break; Case 4: cout<<"--Please divide the operation--\n"; cout<<"--Please enter the number of questions--\n"; CIN>>N; for(i=1; i<=n;i++) {a=rand ()% About+1; b=rand ()% About+1; Res=a/b; cout<<a<<"/"<<b<<"="; CIN>>ans; if(ans==Res) {cout<<"you got the right answer,!\n."; C4++; } Else{cout<<"you answered the wrong question!"<<Endl; cout<<"the correct answer is:"<<res<<Endl; } } Break; Case 5:GotoEND; }}end:cout<<"bye,!\n .";return 0;}
Experiment 1-arithmetic