Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- namespace Form1 {
- 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>
- /// Сводка для MyForm
- /// </summary>
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: добавьте код конструктора
- //
- }
- protected:
- /// <summary>
- /// Освободить все используемые ресурсы.
- /// </summary>
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::GroupBox^ groupBox1;
- protected:
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::NumericUpDown^ numericUpDown1;
- private: System::Windows::Forms::RadioButton^ radioButton1;
- private: System::Windows::Forms::DataGridView^ dataGridView1;
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::MenuStrip^ menuStrip1;
- private: System::Windows::Forms::ToolStripMenuItem^ сгенерироватьМатрицуToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ выводToolStripMenuItem;
- private: System::Windows::Forms::DataGridView^ dataGridView2;
- private: System::Windows::Forms::Label^ label2;
- private: System::Windows::Forms::RadioButton^ radioButton2;
- private: System::Windows::Forms::ToolStripMenuItem^ очиститьToolStripMenuItem;
- 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->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
- this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
- this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
- this->сгенерироватьМатрицуToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->очиститьToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->выводToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->dataGridView2 = (gcnew System::Windows::Forms::DataGridView());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->groupBox1->SuspendLayout();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->BeginInit();
- this->menuStrip1->SuspendLayout();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView2))->BeginInit();
- this->SuspendLayout();
- //
- // groupBox1
- //
- this->groupBox1->Controls->Add(this->radioButton2);
- this->groupBox1->Controls->Add(this->label1);
- this->groupBox1->Controls->Add(this->numericUpDown1);
- this->groupBox1->Controls->Add(this->radioButton1);
- this->groupBox1->Location = System::Drawing::Point(31, 24);
- this->groupBox1->Name = L"groupBox1";
- this->groupBox1->Size = System::Drawing::Size(502, 114);
- this->groupBox1->TabIndex = 0;
- this->groupBox1->TabStop = false;
- //
- // radioButton2
- //
- this->radioButton2->AutoSize = true;
- this->radioButton2->Location = System::Drawing::Point(189, 20);
- this->radioButton2->Name = L"radioButton2";
- this->radioButton2->Size = System::Drawing::Size(67, 17);
- this->radioButton2->TabIndex = 3;
- this->radioButton2->TabStop = true;
- this->radioButton2->Text = L"Вручную";
- this->radioButton2->UseVisualStyleBackColor = true;
- this->radioButton2->CheckedChanged += gcnew System::EventHandler(this, &MyForm::radioButton2_CheckedChanged);
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(186, 55);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(123, 13);
- this->label1->TabIndex = 2;
- this->label1->Text = L"Размерность матрицы";
- //
- // numericUpDown1
- //
- this->numericUpDown1->Location = System::Drawing::Point(215, 71);
- this->numericUpDown1->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1, 0, 0, 0 });
- this->numericUpDown1->Name = L"numericUpDown1";
- this->numericUpDown1->Size = System::Drawing::Size(67, 20);
- this->numericUpDown1->TabIndex = 1;
- this->numericUpDown1->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1, 0, 0, 0 });
- //
- // radioButton1
- //
- this->radioButton1->AutoSize = true;
- this->radioButton1->Checked = true;
- this->radioButton1->Location = System::Drawing::Point(7, 20);
- this->radioButton1->Name = L"radioButton1";
- this->radioButton1->Size = System::Drawing::Size(87, 17);
- this->radioButton1->TabIndex = 0;
- this->radioButton1->TabStop = true;
- this->radioButton1->Text = L"По формуле";
- this->radioButton1->UseVisualStyleBackColor = true;
- this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &MyForm::radioButton1_CheckedChanged);
- //
- // dataGridView1
- //
- this->dataGridView1->AllowUserToAddRows = false;
- this->dataGridView1->AllowUserToDeleteRows = false;
- this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
- this->dataGridView1->Location = System::Drawing::Point(38, 155);
- this->dataGridView1->Name = L"dataGridView1";
- this->dataGridView1->ReadOnly = true;
- this->dataGridView1->Size = System::Drawing::Size(495, 356);
- this->dataGridView1->TabIndex = 1;
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(458, 531);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(75, 70);
- this->button1->TabIndex = 2;
- this->button1->Text = L"Ок";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
- //
- // menuStrip1
- //
- this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
- this->сгенерироватьМатрицуToolStripMenuItem,
- this->очиститьToolStripMenuItem, this->выводToolStripMenuItem
- });
- this->menuStrip1->Location = System::Drawing::Point(0, 0);
- this->menuStrip1->Name = L"menuStrip1";
- this->menuStrip1->Size = System::Drawing::Size(558, 24);
- this->menuStrip1->TabIndex = 3;
- this->menuStrip1->Text = L"menuStrip1";
- //
- // сгенерироватьМатрицуToolStripMenuItem
- //
- this->сгенерироватьМатрицуToolStripMenuItem->Name = L"сгенерироватьМатрицуToolStripMenuItem";
- this->сгенерироватьМатрицуToolStripMenuItem->Size = System::Drawing::Size(152, 20);
- this->сгенерироватьМатрицуToolStripMenuItem->Text = L"Сгенерировать матрицу";
- this->сгенерироватьМатрицуToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::сгенерироватьМатрицуToolStripMenuItem_Click);
- //
- // очиститьToolStripMenuItem
- //
- this->очиститьToolStripMenuItem->Name = L"очиститьToolStripMenuItem";
- this->очиститьToolStripMenuItem->Size = System::Drawing::Size(71, 20);
- this->очиститьToolStripMenuItem->Text = L"Очистить";
- this->очиститьToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::очиститьToolStripMenuItem_Click);
- //
- // выводToolStripMenuItem
- //
- this->выводToolStripMenuItem->Name = L"выводToolStripMenuItem";
- this->выводToolStripMenuItem->Size = System::Drawing::Size(53, 20);
- this->выводToolStripMenuItem->Text = L"Выход";
- this->выводToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::выводToolStripMenuItem_Click);
- //
- // dataGridView2
- //
- this->dataGridView2->AllowUserToAddRows = false;
- this->dataGridView2->AllowUserToDeleteRows = false;
- this->dataGridView2->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
- this->dataGridView2->Location = System::Drawing::Point(133, 517);
- this->dataGridView2->Name = L"dataGridView2";
- this->dataGridView2->ReadOnly = true;
- this->dataGridView2->Size = System::Drawing::Size(280, 84);
- this->dataGridView2->TabIndex = 4;
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Location = System::Drawing::Point(35, 531);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(43, 13);
- this->label2->TabIndex = 5;
- this->label2->Text = L"Вектор";
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(558, 620);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->dataGridView2);
- this->Controls->Add(this->button1);
- this->Controls->Add(this->dataGridView1);
- this->Controls->Add(this->groupBox1);
- this->Controls->Add(this->menuStrip1);
- this->MainMenuStrip = this->menuStrip1;
- this->Name = L"MyForm";
- this->Text = L"Генератор матриц";
- this->groupBox1->ResumeLayout(false);
- this->groupBox1->PerformLayout();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->EndInit();
- this->menuStrip1->ResumeLayout(false);
- this->menuStrip1->PerformLayout();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView2))->EndInit();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- //Создаем функцию Form, которая будет генерировать нашу матрицу по формуле
- private: void form(int size, int **mass) {
- for (int i = 0; i < size; i++)
- {
- for (int j = 0; j < size; j++) {
- mass[i][j] = /*Тут указывам формулу, по которой будет генерироваться матрица, например*/ i + j * 2;
- }
- }
- }
- //Создаем функцию typing для ручного ввода
- private: void typing(int size, int **mass) {
- for (int i = 0; i < size; i++) {
- for (int j = 0; j < size; j++) {
- //Получаем значение из ячеек таблицы
- mass[i][j] = Convert::ToInt32(dataGridView1->Rows[i]->Cells[j]->Value);
- }
- }
- }
- //Создаем функцию clear для очистки таблицы и векторов
- private: void clear() {
- for (int i = 0; i < dataGridView1->Rows->Count; i++) {
- dataGridView2->Rows[0]->Cells[i]->Value = 0;
- for (int j = 0; j < dataGridView1->Rows->Count; j++) {
- dataGridView1->Rows[i]->Cells[j]->Value = 0;
- }
- }
- }
- //Создаем функцию show, которая будет выводить нашу матрицу
- private: void show(int size, int **mass) {
- for (int i = 0; i < size; i++) {
- for (int j = 0; j < size; j++) {
- //Название таблицы (в верхнем левом углу)
- dataGridView1->TopLeftHeaderCell->Value = "Матрица";
- //Вывод номеров столбцов
- dataGridView1->Columns[j]->HeaderCell->Value = Convert::ToString(j + 1);
- //Вывод номеров строк
- dataGridView1->Rows[i]->HeaderCell->Value = Convert::ToString(i + 1);
- //Вывод значений ячеек
- dataGridView1->Rows[i]->Cells[j]->Value = mass[i][j];
- }
- }
- }
- //Создаем функцию vektor, которая будет искать в каждой строке наибольший элемент и записывать в отдельный массив
- private: void vektor(int size, int **mass) {
- //Создаем динамический массив под вектор
- int *vekt = new int[size];
- //Ищем наибольшее значение в каждой строке
- for (int i = 0; i < size; i++) {
- vekt[i] = mass[i][0];
- for (int j = 0; j < size; j++) {
- if (vekt[i] < mass[i][j])
- vekt[i] = mass[i][j];
- }
- }
- //Выводим вектор во вторую таблицу
- for (int i = 0; i < size; i++) {
- dataGridView2->Columns[i]->HeaderCell->Value = Convert::ToString(i + 1);
- dataGridView2->Rows[0]->Cells[i]->Value = vekt[i];
- }
- //Удаляем массив vekt
- delete[] vekt;
- }
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- //Получаем размерность матрицы
- int size = Convert::ToInt32(numericUpDown1->Value);
- //Создаем двумерный динамический массив для нашец матрицы
- int **mass = new int *[size];
- for (int i = 0; i < size; i++) {
- mass[i] = new int[size];
- }
- //Создаем таблицу под матрицу
- dataGridView1->ColumnCount = size;
- dataGridView1->RowCount = size;
- //Создаем таблицу под вектор
- dataGridView2->ColumnCount = size;
- dataGridView2->RowCount = 1;
- //Если выбран вариант "по формуле"
- if (radioButton1->Checked) {
- //Вызываем функцию form, которая будет создавать матрицу по формуле
- form(size, mass);
- }
- //Если выбран вариант "вручную"
- if (radioButton2->Checked) {
- //Вызываем функцию typing для заполнения матрицы значения введенные ввручную
- typing(size, mass);
- }
- //Вызываем функцию show для вывода матрицы
- show(size, mass);
- //Вызываем функцию vektor
- vektor(size, mass);
- //Выравниваем ячейки таблиц
- dataGridView1->AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders);
- dataGridView1->AutoResizeColumns();
- dataGridView2->AutoResizeColumns();
- //Удаляем из памяти массив с матрицей
- for (int i = 0; i < size; i++) {
- delete[] mass[i];
- }
- delete[] mass;
- }
- private: System::Void сгенерироватьМатрицуToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- //Системно нажимаем на кнопку "Ok"
- button1->PerformClick();
- }
- private: System::Void выводToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- //Выводим из приложения
- Application::Exit();
- }
- private: System::Void radioButton2_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
- //Очищаем таблицу
- clear();
- dataGridView1->ReadOnly = false;
- }
- private: System::Void очиститьToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- clear();
- }
- private: System::Void radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
- dataGridView1->ReadOnly = true;
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement