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
| #pragma once
#include "stdafx.h"
#include<math.h>
int m, n,kol,kol2,p;
int A[50][50];
namespace My7var {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Сводка для Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::GroupBox^ groupBox1;
protected:
private: System::Windows::Forms::DataGridView^ dataGridView1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::GroupBox^ groupBox2;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::CheckBox^ checkBox2;
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private:
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->groupBox1->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->BeginInit();
this->groupBox2->SuspendLayout();
this->SuspendLayout();
//
// groupBox1
//
this->groupBox1->Controls->Add(this->dataGridView1);
this->groupBox1->Controls->Add(this->textBox2);
this->groupBox1->Controls->Add(this->textBox1);
this->groupBox1->Controls->Add(this->label4);
this->groupBox1->Controls->Add(this->label3);
this->groupBox1->Controls->Add(this->label2);
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Location = System::Drawing::Point(18, 20);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(429, 250);
this->groupBox1->TabIndex = 0;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Ввод данных матрицы";
//
// dataGridView1
//
this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dataGridView1->ColumnHeadersVisible = false;
this->dataGridView1->Location = System::Drawing::Point(0, 114);
this->dataGridView1->Name = L"dataGridView1";
this->dataGridView1->RowHeadersVisible = false;
this->dataGridView1->Size = System::Drawing::Size(423, 112);
this->dataGridView1->TabIndex = 6;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(307, 54);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(100, 20);
this->textBox2->TabIndex = 5;
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(80, 54);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 4;
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(169, 89);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(87, 13);
this->label4->TabIndex = 3;
this->label4->Text = L"Матрица A[n,m]";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(235, 57);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(66, 13);
this->label3->TabIndex = 2;
this->label3->Text = L"M-столбцов";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(18, 57);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(47, 13);
this->label2->TabIndex = 1;
this->label2->Text = L"N-строк";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(147, 21);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(138, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Задайте размер матрицы";
//
// groupBox2
//
this->groupBox2->Controls->Add(this->textBox4);
this->groupBox2->Controls->Add(this->textBox3);
this->groupBox2->Controls->Add(this->checkBox2);
this->groupBox2->Controls->Add(this->checkBox1);
this->groupBox2->Location = System::Drawing::Point(23, 283);
this->groupBox2->Name = L"groupBox2";
this->groupBox2->Size = System::Drawing::Size(521, 98);
this->groupBox2->TabIndex = 1;
this->groupBox2->TabStop = false;
this->groupBox2->Text = L"Найти";
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(421, 62);
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::Drawing::Size(100, 20);
this->textBox4->TabIndex = 7;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(415, 26);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(100, 20);
this->textBox3->TabIndex = 6;
//
// checkBox2
//
this->checkBox2->AutoSize = true;
this->checkBox2->Location = System::Drawing::Point(14, 64);
this->checkBox2->Name = L"checkBox2";
this->checkBox2->Size = System::Drawing::Size(401, 17);
this->checkBox2->TabIndex = 1;
this->checkBox2->Text = L"количество отрицательных элементов находящихся в главной диагонали";
this->checkBox2->UseVisualStyleBackColor = true;
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = System::Drawing::Point(14, 28);
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = System::Drawing::Size(271, 17);
this->checkBox1->TabIndex = 0;
this->checkBox1->Text = L"Найти количество элементов, меньших числа 5 ";
this->checkBox1->UseVisualStyleBackColor = true;
//
// button1
//
this->button1->Location = System::Drawing::Point(8, 387);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 34);
this->button1->TabIndex = 2;
this->button1->Text = L"Создать таблицу";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(89, 387);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(185, 34);
this->button2->TabIndex = 3;
this->button2->Text = L"Перенести данные из таблицы в массив и решить задание";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(280, 387);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(75, 34);
this->button3->TabIndex = 4;
this->button3->Text = L"Выход";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(556, 433);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedToolWindow;
this->Name = L"Form1";
this->Text = L"Form1";
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->EndInit();
this->groupBox2->ResumeLayout(false);
this->groupBox2->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
//Проверка, что не пустые компоненты textBox1 и textBox2
if ((textBox1->Text!="")&&(textBox2->Text!=""))
{m = Convert::ToInt32(textBox1->Text);
n = Convert::ToInt32(textBox2->Text);
//Чистка столбцов компонента DataGridView, если они не пусты
dataGridView1->Columns->Clear();
//Заполнение компонента DataGridView столбцами
dataGridView1->ColumnCount = n;
//Заполнение компонента DataGridView строками
dataGridView1->RowCount = m;}
else
{MessageBox::Show( "Заполните, пожалуйста, данные", "Ошибка ввода данных", MessageBoxButtons::OK, MessageBoxIcon::Exclamation );}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
//переменную kol и kol2 обнуляем, а переменную р присваиваем единице,
kol=0;kol2=0;p=1;
//Производим считывание из ячеек таблицы и вносим данные в массив
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
{
A[i][j] = Convert::ToSingle(this->dataGridView1->Rows[i]->Cells[j]->Value);
if (A[i][j]<5) {p=A[i][j]++;kol2++;}
if (A[i][j]%2==0) {kol++;}
}
//Вывод данных нахождения произведения отрицательных элементов матрицы
if ((checkBox1->Checked==true)&&(kol2!=0)) {this->textBox3->Text=Convert::ToString (p);}
else
if (checkBox1->Checked==true) {this->textBox3->Text=Convert::ToString ("нет элементов");}
//Вывод данных нахождения количество четных элементов матрицы
if ((checkBox2->Checked==true)&&(kol!=0)) {this->textBox4->Text=Convert::ToString (kol);}
else
if (checkBox2->Checked==true) {this->textBox4->Text=Convert::ToString ("нет элементов");}
return;
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
};
} |