This repository has been archived by the owner on Feb 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
373 lines (311 loc) · 11 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
namespace PolinomialOperations
{
public partial class Form1 : Form
{
int prime = 2;
int degree = 1;
int fieldSize = 0;
static int MAX_DEGREE = 6;
static int MIN_DEGREE = 1;
static int MAX_PRIME = 100;
static int MIN_PRIME = 2;
ArrayList boxes = new ArrayList();
ArrayList labels = new ArrayList();
ArrayList polinom1Boxes = new ArrayList();
ArrayList polinom1Labels = new ArrayList();
ArrayList polinom2Boxes = new ArrayList();
ArrayList polinom2Labels = new ArrayList();
Field field;
ArrayList elements;
int polinom1Size;
int polinom2Size;
ArrayList firstPolinomialArray = new ArrayList();
ArrayList secondPolinomialArray = new ArrayList();
public Form1()
{
InitializeComponent();
polinom1Labels.Add(label100);
polinom1Labels.Add(label101);
polinom1Labels.Add(label102);
polinom1Labels.Add(label103);
polinom1Labels.Add(label104);
polinom1Labels.Add(label105);
polinom1Labels.Add(label106);
polinom1Labels.Add(label107);
polinom1Labels.Add(label108);
polinom1Labels.Add(label109);
polinom1Labels.Add(label110);
polinom1Boxes.Add(comboBox100);
polinom1Boxes.Add(comboBox101);
polinom1Boxes.Add(comboBox102);
polinom1Boxes.Add(comboBox103);
polinom1Boxes.Add(comboBox104);
polinom1Boxes.Add(comboBox105);
polinom1Boxes.Add(comboBox106);
polinom1Boxes.Add(comboBox107);
polinom1Boxes.Add(comboBox108);
polinom1Boxes.Add(comboBox109);
polinom1Boxes.Add(comboBox110);
polinom2Labels.Add(label200);
polinom2Labels.Add(label201);
polinom2Labels.Add(label202);
polinom2Labels.Add(label203);
polinom2Labels.Add(label204);
polinom2Labels.Add(label205);
polinom2Labels.Add(label206);
polinom2Labels.Add(label207);
polinom2Labels.Add(label208);
polinom2Labels.Add(label209);
polinom2Labels.Add(label210);
polinom2Boxes.Add(comboBox200);
polinom2Boxes.Add(comboBox201);
polinom2Boxes.Add(comboBox202);
polinom2Boxes.Add(comboBox203);
polinom2Boxes.Add(comboBox204);
polinom2Boxes.Add(comboBox205);
polinom2Boxes.Add(comboBox206);
polinom2Boxes.Add(comboBox207);
polinom2Boxes.Add(comboBox208);
polinom2Boxes.Add(comboBox209);
polinom2Boxes.Add(comboBox210);
}
public static string ReverseString(string s)
{
char[] arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
private bool isPrimeNumber(int number)
{
if (number == 0 || number == 1)
{
return false;
}
else
{
for (int iterator = 2; iterator <= number / 2; iterator++)
{
if (number % iterator == 0)
{
return false;
}
}
return true;
}
}
private void initializeField() {
boxes.Add(comboBox1);
boxes.Add(comboBox2);
boxes.Add(comboBox3);
boxes.Add(comboBox4);
boxes.Add(comboBox5);
boxes.Add(comboBox6);
boxes.Add(comboBox7);
labels.Add(label3);
labels.Add(label4);
labels.Add(label5);
labels.Add(label6);
labels.Add(label7);
labels.Add(label8);
labels.Add(label9);
button4.Visible = true;
if (degree != 1)
{
label10.Visible = true;
((Label)labels[degree]).Text = "x^" + degree;
for (int i = 0; i <= degree; i++)
{
((ComboBox)boxes[i]).Visible = true;
((Label)labels[i]).Visible = true;
}
}
else
{
label10.Visible = false;
for (int i = 0; i <= MAX_DEGREE; i++)
{
((ComboBox)boxes[i]).Visible = false;
((Label)labels[i]).Visible = false;
}
}
for(int i = 0; i < boxes.Count; i++)
{
((ComboBox)boxes[i]).Items.Clear();
for (int element = 0; element < prime; element++)
{
((ComboBox)boxes[i]).Items.Add(element);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
prime = Convert.ToInt32(textBox1.Text);
if(prime > MAX_PRIME || prime < MIN_PRIME)
{
throw new Exception();
}
if (!isPrimeNumber(prime))
{
throw new Exception();
}
degree = Convert.ToInt32(textBox2.Text);
if(degree > MAX_DEGREE || degree < MIN_DEGREE)
{
throw new Exception();
}
initializeField();
fieldSize = intPow(prime, degree);
}
catch (Exception)
{
MessageBox.Show("Проверьте корректность введёных данных");
return;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label8_Click(object sender, EventArgs e)
{
}
private void label7_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private int intPow(int number, int deg)
{
int result = 1;
for(int i = 0; i < deg; i++)
{
result = result * number;
}
return result;
}
private void button4_Click(object sender, EventArgs e)
{
ArrayList primitivePolinomial = new ArrayList();
for(int i = 0; i <= degree; i++)
{
primitivePolinomial.Add(Convert.ToInt32(((ComboBox)boxes[i]).Text));
}
field = new Field(fieldSize, prime, primitivePolinomial);
if (field.isPrimitivePolinomial(primitivePolinomial) || degree == 1)
{
button4.Visible = false;
label23.Visible = true;
label24.Visible = true;
comboBox51.Visible = true;
comboBox52.Visible = true;
}
else
{
//ввод заного
}
}
void inputPolinomials()
{
label35.Visible = true;
label36.Visible = true;
((Label)polinom1Labels[polinom1Size - 1]).Text = "x^" + (polinom1Size - 1);
((Label)polinom2Labels[polinom2Size - 1]).Text = "x^" + (polinom2Size - 1);
for (int i = 0; i < polinom1Size; i++)
{
((ComboBox)polinom1Boxes[i]).Visible = true;
((Label)polinom1Labels[i]).Visible = true;
}
for (int i = 0; i < polinom2Size; i++)
{
((ComboBox)polinom2Boxes[i]).Visible = true;
((Label)polinom2Labels[i]).Visible = true;
}
elements = field.getElements();
for(int i = 0; i < polinom1Size; i++)
{
for(int j = 0; j < elements.Count; j++)
{
((ComboBox)polinom1Boxes[i]).Items.Add(Field.elementToString((ArrayList)elements[j]));
}
}
for (int i = 0; i < polinom2Size; i++)
{
for (int j = 0; j < elements.Count; j++)
{
((ComboBox)polinom2Boxes[i]).Items.Add(Field.elementToString((ArrayList)elements[j]));
}
}
}
private void label11_Click(object sender, EventArgs e)
{
}
private void comboBox12_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox11_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox14_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
try
{
polinom1Size = Convert.ToInt32(comboBox51.Text);
polinom2Size = Convert.ToInt32(comboBox52.Text);
inputPolinomials();
}
catch (Exception)
{
MessageBox.Show("Проверьте корректность введёных данных");
return;
}
}
private void button6_Click(object sender, EventArgs e)
{
for(int i = 0; i < polinom1Size; i++)
{
firstPolinomialArray.Add(elements[((ComboBox)polinom1Boxes[i]).SelectedIndex]);
}
for (int i = 0; i < polinom2Size; i++)
{
secondPolinomialArray.Add(elements[((ComboBox)polinom2Boxes[i]).SelectedIndex]);
}
Polinomial firstPolinomial = new Polinomial(firstPolinomialArray, field);
Polinomial secondPolinomial = new Polinomial(secondPolinomialArray, field);
Polinomial result;
switch (comboBox8.SelectedItem.ToString())
{
case "+":
result = firstPolinomial.sum(firstPolinomial, secondPolinomial);
textBox3.Text = result.polinomialToString();
break;
case "-":
result = firstPolinomial.difference(firstPolinomial, secondPolinomial);
textBox3.Text = result.polinomialToString();
break;
case "*":
result = firstPolinomial.multiply(firstPolinomial, secondPolinomial);
textBox3.Text = result.polinomialToString();
break;
case "|":
result = firstPolinomial.divide(firstPolinomial, secondPolinomial);
textBox3.Text = result.polinomialToString();
break;
}
}
}
}