Arithmetic Design 03

Source: Internet
Author: User
Tags net time

Topic Requirements

1 The program that the student writes must be able to determine whether the user's input answers are correct

2 The program must be able to handle arithmetic mixed formulas

1 Design ideas:

Generate random numbers and number of numbers generated in the topic

Determine if the condition is met by the IF

Use the For loop to achieve the number of calculations required to produce

In the concrete implementation process, by comparing the user answer and the program to run the answer to determine the right and wrong answer

2 Source program code:

#include <iostream>#include <ctime>#include <cstdlib>using namespaceStd;voidMain () {intPronum; IntFanwei; IntFushu; IntYushu; IntChengchu; IntKuohao; cout<< "Please enter the number of questions you want (please enter an integer)" <<Endl Cin>>Pronum; cout<< "Please enter the minimum value range (0~100)" <<Endl Cin>>Fanwei; cout<< "Please select whether there is a negative number Select 1 indicates that there is a choice 0 means no (Please select 1 or 0 as required)" <<Endl Cin>>Fushu; cout<< "Please select whether the number of 3 indicates that there is a choice 4 means no (please select 3 or 4 as required)" <<Endl Cin>>Yushu; cout<< "Please select whether there is multiplication 5 indicates that there is a choice 6 means no (Please select 5 or 6 as required)" <<Endl Cin>>Chengchu; cout<< "Please select if there is a bracket of 7 indicating that there is a choice 8 means no (Please select 7 or 8 as required)" <<Endl Cin>>Kuohao; int num[10]; IntMyanswer,answer; int rinum=0; int fanum=0; int zff=0, fhnum=0; Char fs[20]; Char fuhao[20]; IntWeizhi1; IntWeizhi2; Srand (Time (0)); for (int i=0;i<pronum;i++) {int Shuzinum=rand ()%4+2; for (int j=0;j<=shuzinum;j++) {Num[j]=rand ()%100+1; For(;;) {if (num[j]<Fanwei) Num[j]=rand ()%100+1; else break; } if (fushu==1) {Zff=rand ()%2; if (zff==0) fs[j]= '-'; if (fs[j]== '-') num[j]=num[j]* (-1); if (zff==1) fs[j]= ' + '; } if (fushu==0) {fs[j]= ' + '; }} for (int ii=0;ii<shuzinum;ii++) {if (chengchu==5) {Fhnum=rand ()%4; if (fhnum==0) fuhao[ii]= ' + '; if (fhnum==1) fuhao[ii]= '-'; if (fhnum==2) fuhao[ii]= ' * '; if (fhnum==3) {fuhao[ii]= '/'; if (yushu==3) {weizhi1=ii For(;;) {if (num[ii]%num[ii+1]!=0) Break; Else{Num[ii]=rand ()%100+1; Num[ii+1]=rand ()%100+1; }}} if (yushu==4) {weizhi1=ii For(;;) {if (num[ii]%num[ii+1]!=0) {Num[ii]=rand ()%100+1; Num[ii+1]=rand ()%100+1; } else break; }}} if (chengchu==6) {Fhnum=rand ()%2; if (fhnum==0) fuhao[ii]= ' + '; if (fhnum==1) fuhao[ii]= '-'; }} cout<<i+1<< ":" <<num[0]; if (shuzinum==2) kuohao=8; if (kuohao==7) {weizhi2 =rand ()% (shuzinum-2) +1; for (int i=0;i<weizhi2-1;i++) {cout<<fuhao[i]<<num[i+1]; } cout<<fuhao[weizhi2-1]<< "(" <<num[weizhi2]<<fuhao[weizhi2]<<num[weizhi2 +1]< < ")"; for (int i=weizhi2 +1;i<shuzinum;i++) {cout<<fuhao[i]<<num[i+1]; } answer=num[0]; if (fuhao[weizhi2]== ' + ')) {Num[weizhi2]=num[weizhi2]+num[weizhi2 +1]; Num[weizhi2 +1]=0; } if (fuhao[weizhi2]== '-') {num[weizhi2]=num[weizhi2]-num[weizhi2+1]; Num[weizhi2+1]=0; } if (fuhao[weizhi2]== ' * ') {num[weizhi2]=num[weizhi2]*NUM[WEIZHI2]; Num[weizhi2+1]=1; } if (fuhao[weizhi2]== '/') {num[weizhi2]=num[weizhi2]/num[weizhi2+1]; Num[weizhi2+1]=1; } for (int i=0;i<shuzinum;i++{if (fuhao[i]== ' * ')) {num[i]=num[i]*num[i+1]; Num[i+1]=1; } if (fuhao[i]== '/') {num[i]=num[i]/num[i+1]; Num[i+1]=1; }} for (int i=0;i<shuzinum;i++) {if (fuhao[i]== ' + ')) answer=answer+num[i+1]; if (fuhao[i]== '-') answer=answer-num[i+1]; if (fuhao[i]== ' * ') answer=answer*num[i+1]; if (fuhao[i]== '/') answer=answer/num[i+1]; }} if (kuohao==8) {for (int i=1;i<shuzinum;i++) {cout<<fuhao[i]<<num[i+1]; } answer=num[0]; for (int i=0;i<shuzinum;i++) {if (fuhao[i]== ' * ' ) {num[i]=num[i]*num[i+1 ]; num[i+1]=1 ;} if (fuhao[i]== '/' ) {num[i]= Num[i]/num[i+1 ]; num[i+1]=1 ;}} for (int i=0;i<shuzinum;i++ ) {if (fuhao[i]== ' + ' ) answer= Answer+num[i+1 ]; if (fuhao[i]== '-' ) answer=answer-num[i+1 ]; if (fuhao[i]== ' * ' ) answer=answer * Num[i+1 ]; if (fuhao[i]== '/' ) answer=answer/num[i+1 ];}} cout<< "=" <<  Endl; cout << "Please enter your calculation results" <<  Endl; cin>>  myanswer; if (answer-myanswer<0.00001 ) {rinum++  cout<< "Congratulations on your <<  Endl;} else  {fanum++ ; cout<<" I'm sorry Wrong "<<  Endl ; }} cout<< "was right:" <<RiNum<< "<<" was wrong: "<<FaNum<<" <<  Endl;} 
3 Run Results


4 Experiment Summary: Through this experiment, I understand the importance of companion. Two a person's mind collision is indeed much better than a man's thoughts. This cooperation reminds me of the importance of the group, which makes me understand the key to cooperation.

Time log:

Study Chen Chen Date: 3/26

Teacher: Wang Course: Introduction to Software engineering

Date

Start time

End time

Middle Time (minutes)

NET time

Minutes

Activities

Note

3/21

8:00

9:50

10

100

Class

Break at recess

3/22

19:00

22:00

120

Write a program

3/23

21:30

22:20

0

50

Write a program

3/24

20:00

22:15

75

Writing Programs

3/25

19:30

22:30

0

30

Writing procedures and surfing the web for information learning

3/26

10:30

5:36

0

157

Write procedures, check information

Work Photo:

Arithmetic Design 03

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.