Arithmetic Operator 3 and Arithmetic Operator 4
I. Lab questions
This time, my program is further extended to arithmetic 2 of the four arithmetic operations.
I chose the first direction: the program can accept the answers entered by the user, determine the right and wrong, and finally provide a total of right and wrong numbers.
Ii. Idea of experiment Extension
1. Because I have compiled a serial number for each question, you only need to enter the answer in the order of the question.
2. Right or wrong. I defined an array in advance to store the correct answer, and finally compared the answer entered by the user with the correct answer.
3. Give the number of right/wrong values. This is relatively easy. You only need to design two variables, one for calculating the correct number, and the other for calculating the number of errors. Finally, give the answer.
Iii. Experiment code
// Author: Xin 1-2 -2 class division xinhong # include <iostream. h> # include <stdlib. h> # include <time. h> void hycc () {int f; // defines the number of hexadecimal cout operations to be tested. <"Enter the four arithmetic operations to be tested in hexadecimal notation? "<Endl; cin> f; int x, y, z, t; // x, y represents the two numbers generated, respectively. z is used to control addition, subtraction, multiplication, division, and int e; // enter the number of arithmetic questions in each row srand (time (NULL); int n; int B; // indicates whether there are negative int a; // enter the row spacing int d; // float daan [100] represents the input answer; // represents the correct answer int zq = 0; // represents the number of correct answers int cw = 0; // indicates the number of wrong answers. cout <"How many mathematical questions need to be listed? "<Endl; cin> n; // n indicates the number of questions. cout <" does the addition/subtraction have negative numbers? (0 indicates a negative number, and 1 indicates no negative number) "<endl; cin> B; cout <" How many arithmetic questions do each line need to print? "<Endl; cin> e; cout <" what is the row spacing when printing? "<Endl; cin>; cout <"********************************" <endl; for (int I = 0; I <n; I ++) {x = rand () % f; y = rand () % f; z = rand () % 4; switch (z) {case 0: cout <I + 1 <"," <x <"+" <y <"=" <""; daan [I + 1] = x + y; break; case 1: if (B = 1) {if (x <y) {t = x; x = y; y = t ;}cout <I + 1 <"," <x <"-" <y <"=" <"";} else if (B = 0) {cout <I + 1 <"," <x <"-" <y <"=" <"";} daan [I + 1] = x-y; break; case 2: cout <I + 1 <"," <x <"*" <y <"=" <""; daan [I + 1] = x * y; break; Case 3: if (y! = 0) {cout <I + 1 <"," <x <"weight" <y <"=" <"";} else {I = I-1;} daan [I + 1] = (float) x/y; break; default: cout <"out of Test Range" <endl; break ;} if (I + 1) % e = 0) {for (int c = 0; c <= a; c ++) {cout <endl ;}} if (I + 1) = n) {cout <endl ;}}for (I = 1; I <= n; I ++) {cout <"Please answer:" <endl; cout <I <","; cin> d; if (d = daan [I]) {cout <"congratulations, the answer is correct! "<Endl; cout <endl; zq = zq + 1;} else {cout <" an error is returned. The correct answer is: "<" "<daan [I] <endl; cout <endl; cw = cw + 1 ;}} cout <" the number of correct answers is: "<" "<zq <" <endl; cout <"the number of errors answered is: "<" "<cw <" <endl;} void bhycc () {int f; cout <"Enter the four arithmetic operations to be tested in hexadecimal notation? "<Endl; cin> f; int e; // enter the number of arithmetic questions in each row: int x, y, z, t; // x, y indicates the two numbers generated, and z is used to control addition, subtraction, multiplication, and Division srand (time (NULL); int n; // n indicates the number of questions int B; // indicates whether the addition or subtraction has negative int a; // It is used to input the line spacing int d; // It indicates the input answer int daan [100]; // It indicates the correct answer int zq = 0; // used to indicate the number of correct answers int cw = 0; // used to indicate the number of wrong answers cout <"How many mathematical questions need to be listed" <endl; cin> n; // n indicates the cout of the question. <"does the addition/subtraction have a negative number? (0 indicates a negative number, and 1 indicates no negative number) "<endl; cin> B; cout <" How many arithmetic questions do each line need to print? "<Endl; cin> e; cout <" what is the row spacing when printing? "<Endl; cin>; cout <"********************************" <endl; for (int I = 0; I <n; I ++) {x = rand () % f; y = rand () % f; z = rand () % 2; switch (z) {case 0: cout <I + 1 <"," <x <"+" <y <"=" <""; daan [I + 1] = x + y; break; case 1: if (B = 1) {if (x <y) {t = x; x = y; y = t ;}cout <I + 1 <"," <x <"-" <y <"=" <"";} else if (B = 0) {cout <I + 1 <"," <x <"-" <y <"=" <"";} daan [I + 1] = x-y; break; default: cout <"Beyond Test Range" <endl; break;} if (I + 1) % e = 0) {for (int c = 0; c <= A; c ++) {cout <endl ;}}if (I + 1) = n) {cout <endl ;}} for (I = 1; I <= n; I ++) {cout <"Please answer:" <endl; cout <I <","; cin> d; if (d = daan [I]) {cout <"congratulations, correct answer! "<Endl; cout <endl; zq = zq + 1;} else {cout <" an error is returned. The correct answer is: "<" "<daan [I] <endl; cout <endl; cw = cw + 1 ;}} cout <" the number of correct answers is: "<" "<zq <" <endl; cout <"the number of errors answered is: "<" "<cw <" cw "<endl ;}int main () {int c; // c indicates whether the input is a continuous numeric char ch; cout <"Does cout support multiplication and division? (Y/N) "<endl; cin> ch; if (ch = 'y' | ch = 'y') {hycc (); cout <"********************************" <endl ;} else if (ch = 'n' | ch = 'n') {bhycc (); cout <"********************************" <endl ;} else {cout <"input error. You cannot answer this question! "<Endl ;}cout <" do you want to continue answering questions? (0: Continue 1: Exit) "<endl; cin> c; if (c = 0) {cout <endl; main ();} else {cout <endl; return 0;} return 0 ;}
Result
V. Summary
There are several choices for this question. Due to my poor programming ability, I chose the first direction and encountered some difficulties in programming, such as division, because the array defining the correct answer is an integer, Division calculation is always incorrect. So I chose to define the array as a floating point. I will contact you more in the future and try to achieve another direction.
PSP
Student ssinhong
Date: 2014.3.17
Instructor Wang Jianmin
Program No _______________
Project Plan Summary
|
Programming |
Read books |
After-school review |
Daily total |
Sunday |
|
|
|
|
Monday |
|
|
|
|
Tuesday |
30 |
30 |
90 |
150 |
Wednesday |
90 |
30 |
|
120 |
Thursday |
120 |
30 |
|
150 |
Friday |
|
|
|
|
Saturday |
|
|
|
|
Weekly total |
240 |
90 |
90 |
420 |
Time record summary
Date |
Start |
End |
Interruption time |
NET Time |
Activity |
Remarks |
C |
U |
March 17 |
4: 00 |
5: 00 |
None |
160 |
Programming |
|
|
|
|
8: 00 |
9: 30 |
30 |
60 |
Review |
Write homework |
|
|
|
10: 00 |
10: 30 |
None |
30 |
Read books |
|
|
|
March 18 |
10: 00 |
|
15 |
75 |
Programming |
Rest |
|
|
|
10: 00 |
10: 30 |
None |
30 |
Read books |
|
|
|
March 19 |
7: 00 |
9: 00 |
None |
120 |
Programming |
|
|
|
Defect record log
Date |
No. |
Type |
Introduction phase |
Exclusion phase |
Time repaired |
Repair defects |
March 17 |
01 |
Program |
Encoding |
Compile |
20 min |
An error is reported when the maximum value of a few numbers is obtained. Finally, I put the sum in an array. |
March 18 |
02 |
Program |
Encoding |
Compile |
10 min |
I forgot to assign a value to the number of correct answers and the number of wrong answers. |
|
03 |
Program |
Encoding |
Compile |
30 min |
When calculating the correct answer to division, it cannot be a floating point type. Then I define the answer array as a floating point type. |
March 19 |
04 |
Program |
Encoding |
Compile |
10 min |
In a function without multiplication and division, you forget to assign values to the correct answer, resulting in an error in the result. |
|
05 |
Program |
Encoding |
Compile |
10 min |
Variable usage error. No response is returned during running. |