许久没有编程了,最基本的也要错,对自己一个小小的++写成了--居然改了许久许久,十分的失望,我觉得老师多布置这种题目是非常好的,让我们有紧迫感。。。。下面是时间表:
三月十五日晚上,开始思考怎么搞定 |
用时25分钟 |
三月16日开始编写各自模块的程序 |
用时75分钟 |
三月18日开始找错 |
许久找不出来,改了又改 |
三月19日,上传代码 |
|
1 #include <iostream>
2 #include<stdlib.h>
3 #include <ctime>
4 using namespace std;
5 #include <cmath>
6
7 void main()
8 {
9 int i, j, a, b[1000], c[1000], d[1000], e, min, max, pj;//a是份数,
10 int aa, bb, cc,s;//各参数为定义量
11 srand((unsigned)time(NULL));
12 cout << "请输入你想打印的题数:" << endl;
13 cin >> a;
14 cout << "请输入随机数的范围值,min与max的值分别为:" << endl;
15 cin >> min >> max;
16 pj = max - min;//范围圈
17 cout << "是否需要乘除?回答1或0:" << endl;
18 cin >> aa;
19 if (aa == 1)
20 {
21 cout << "是否需要除法要得到余数?回答1或0:" << endl;
22 cin >> bb;
23 cout << endl;
24 }
25 cout << "是否需要负数?回答1或0:" << endl;
26 cin >> cc;
27 if (aa == 1)
28 {
29 for (i = 0; i < a; i++)//判断是否重复
30 {
31 b[i] = rand() % pj + min;
32 c[i] = rand() % pj + min;
33 d[i] = rand() % 4;
34 for (j = 0; j < i; j++)
35 {
36 while (b[j] == b[i] && c[j] == c[i]&&d[i]==d[j])
37 {
38 b[i] = rand() % pj + min;
39 c[i] = rand() % pj + min;
40 d[i] = rand() % 4;
41 }
42 }
43 }
44 for (i = 0; i < a; i++)
45 {
46 e = rand() % 2;
47 switch (d[i])
48 {
49 case 0:
50 cout << b[i] << " + " << c[i] << " = " << endl; break;
51 case 1:
52 if (cc == 0)
53 {
54 if (b[i] < c[i])
55 {
56 s = b[i];
57 b[i] = c[i];
58 c[i] = s;
59 }
60 else
61 cout << b[i] << " - " << c[i] << " = " << endl; break;
62 }
63 else
64 cout << b[i] << " - " << c[i] << " = " << endl; break;
65 case 2:
66 if (e == 0)
67 {
68 cout << b[i] << " * " << c[i] << " = " << endl; break;
69 }
70 else if (e == 1)
71 {
72 cout << b[i] << " * ( - " << c[i] << " ) = " << endl; break;
73 }
74 case 3:
75 if (c[i] == 0)//分母不能为零
76 {
77 i--; break;
78 }
79 else if (bb == 1)
80 {
81 if (b[i] % c[i] != 0)
82 {
83 cout << b[i] << " / " << c[i] << " = " << endl; break;
84 }
85 else
86 {
87 i--; break;
88 }
89 }
90 else if (bb == 0)
91 {
92 if (b[i] % c[i] != 0)
93 {
94 cout << b[i] << " / " << c[i] << " = " << endl; break;
95 }
96 else
97 {
98 i--; break;
99 }
100 }
101 break;
102 }
103 }
104 }
105 else
106 {
107 for (i = 0; i < a; i++)//判断是否重复
108 {
109 b[i] = rand() % pj + min;
110 c[i] = rand() % pj + min;
111 d[i] = rand() % 2;
112 for (j = 0; j < i; j++)
113 {
114 while (b[j] == b[i] && c[j] == c[i])
115 {
116 b[i] = rand() % pj + min;
117 c[i] = rand() % pj + min;
118 d[i] = rand() % 2;
119 }
120 }
121 }
122 for (i = 0; i < a; i++)
123 {
124 switch (d[i])
125 {
126 case 0:
127 cout << b[i] << " + " << c[i] << " = " << endl; break;
128 case 1:
129 if (cc == 0)
130 {
131 if (b[i] < c[i])
132 {
133 s = b[i];
134 b[i] = c[i];
135 c[i] = s;
136 }
137 else
138 {
139 cout << b[i] << " - " << c[i] << " = " << endl; break;
140 }
141 }
142 else
143 {
144 cout << b[i] << " - " << c[i] << " = " << endl; break;
145 }
146 }
147 }
148 }
149 }
![](//images0.cnblogs.com/blog2015/724841/201503/191013582985209.png)