Elementary school student second Grade Arithmetic 2.0

Source: Internet
Author: User

On the basis of the original, want to add the score of arithmetic.

This program realizes the function: 30 arithmetic problem writing (not repeating)

Supports integral type arithmetic and fractional arithmetic

Can make a number of quiz

1//Start programming Time: 15:18 2//End Programming Time: 16:42 3 #include <iostream> 4 #include <time.h> 5 #include <stdlib.h> 6 usin G namespaceStd 7 #define MAX 8 #define N 9 intMain () 10{One srand (time (NULL)); seed12 intnum1,num2,num3,num4;13 inti,j,m;14 Char ysf[4]={' + ', '-', ' * ', '/'};15 for (m=0;m<n;m++) 16{J=rand ()%2;//Generate 0 or 118 if (j==0)//integer arithmetic 19{I=rand ()%4;//Generate 0-3 random number of Num1=rand ()% Max;//Generate 0-max-1 random number of num2=rand ()%max;23 switch(i) {case 0://integer added cout<<num1<<ysf[i]<<num2<< "=" <<Endl;26 break; Case 1://Integer subtraction cout<<num1<<ysf[i]<<num2<< "=" <<endl;29 break; case 2://integer multiplied by cout<<num1<<ysf[i]<<num2<< "=" <<Endl;32 break, Case 3://integer divide num2==0) 35 {//Divisor not 036 num2=rand ()%Max;; 37}38 cout<<num1<<ysf[i]<<num2<< "=" <<endl;39 break;: Break;} 42}43 else if (j==1)//score Arithmetic 44{I=rand ()%4; Num1=rand ()%max;47 Num2=rand ()%max;48 while (num2==0| | NUM1&GT;=NUM2) {//fractional denominator not 0 and numerator cannot be greater than denominator num1=rand ()%Max;50 Num2=rand ()%Max;51}52 Num3=rand ()%max;53 Num4=rand ()%max;54 while (num4==0| | NUM3&GT;=NUM4) {//fractional denominator not 0 and numerator cannot be greater than denominator num3=rand ()%max;56 Num4=rand ()%max;57}58 switch(i) {cout<<num1<< case 0://score added to "/" <<num2<<ysf[i]<<num3<< "/" <<num4< < "=" <<endl;61 break; 1://Fractional subtraction cout<<num1<< "/" <<num2<<ysf[i]<<num3<< "/" <<num4<< "=" <<endl;64 break; 2://fractions multiplied by cout<< "(" <<num1<< "/" <<num2<< ")" <<ysf[i]<< "(" <<num3<< "/" <<num4<< ")" << "=" < <endl;67 break; 3://fractions divided by a while (num3==0) {//the fraction of the denominator is not 070 num3=rand ()% max;71 while (num3>= num4) {Num3=rand ()% max;73 num4=rand ()% max;74}75 }76 cout<< "(" <<num1<< "/" <<n um2<< ")" <<ysf[i]<< "(" <<num3<< "/" <<num4<< ")" << "=" <<  endl;77 break; default: }81 }82 }83} /c12> 

The program runs as follows:

Elementary school student second Grade Arithmetic 2.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.