Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int *chislo = new int[matrix.columns];
- for (int j = 0; j < matrix.columns; j++) {
- chislo[j] = 0;
- }
- cout << "nnПроверка на подходимость числа:" << endl;
- // Проверка на подходимость и занесение подходящих чисел в массив chislo
- for (int i = 0; i < matrix.rows; i++) {
- for (int j = 0; j < matrix.columns; j++) {
- if (matrix.ptr[i][j] % 2 == -1) {
- cout << " +"; // отладочный вывод
- chislo[j] += matrix.ptr[i][j];
- }
- else {
- cout << " -"; // отладочный вывод
- chislo[j] += 0;
- }
- }
- cout << endl;
- }
- cout << endl;
- for (int i = 1; i < matrix.columns; ++i) {
- size_t smallest_stolb = matrix.columns - i;
- // находим самый маленькую характеристику столбов
- for (int j = 0; j < matrix.columns - i; j++)
- if (chislo[j] < chislo[smallest_stolb])
- smallest_stolb = j;
- // столбы меняем, и их характеристику
- for (int j = 0; j < matrix.rows; j++) {
- int tmp = matrix.ptr[j][matrix.columns - i];
- matrix.ptr[j][matrix.columns - i] = matrix.ptr[j][smallest_stolb];
- matrix.ptr[j][smallest_stolb] = tmp;
- }
- { int temp = chislo[matrix.columns - i];
- chislo[matrix.columns - i] = chislo[smallest_stolb];
- chislo[smallest_stolb] = temp; }
- }
- cout << "Отсортированные характеристики:" << endl;
- // Проверял такой массив:
- // -3 -5 1 0
- // 1 -3 -1 0
- // -2 3 0 0
- // Проверка корректного занесения подходящих чисел со столбцов матрицы в одномерный массив chislo
- for (int j = 0; j < matrix.columns; j++) {
- cout << chislo[j] << " "; // отладочный вывод
- }
- cout << "n" << endl;
- cout << "Отсортированная матрица:" << endl;
- outputMatrix(matrix);
- #pragma once
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <cstdlib>
- struct Matrix {
- int rows;
- int columns;
- int** ptr;
- };
- Matrix matrix;
- #pragma once
- #include "Header.h"
- namespace Engineering6 {
- 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::DataGridView^ dataGridView1;
- private: System::Windows::Forms::TextBox^ textBox1;
- private: System::Windows::Forms::TextBox^ textBox2;
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Label^ label2;
- private: System::Windows::Forms::Label^ label3;
- private: System::Windows::Forms::Label^ label4;
- private: System::Windows::Forms::Label^ label5;
- private: System::Windows::Forms::Label^ label6;
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::DataGridView^ dataGridView2;
- protected:
- protected:
- private:
- /// <summary>
- /// Обязательная переменная конструктора.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Требуемый метод для поддержки конструктора — не изменяйте
- /// содержимое этого метода с помощью редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
- this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
- this->textBox1 = (gcnew System::Windows::Forms::TextBox());
- this->textBox2 = (gcnew System::Windows::Forms::TextBox());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->label3 = (gcnew System::Windows::Forms::Label());
- this->label4 = (gcnew System::Windows::Forms::Label());
- this->label5 = (gcnew System::Windows::Forms::Label());
- this->label6 = (gcnew System::Windows::Forms::Label());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->dataGridView2 = (gcnew System::Windows::Forms::DataGridView());
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView2))->BeginInit();
- this->SuspendLayout();
- //
- // dataGridView1
- //
- this->dataGridView1->AllowUserToAddRows = false;
- this->dataGridView1->AllowUserToDeleteRows = false;
- this->dataGridView1->AllowUserToResizeColumns = false;
- this->dataGridView1->AllowUserToResizeRows = false;
- this->dataGridView1->BackgroundColor = System::Drawing::SystemColors::Control;
- this->dataGridView1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
- this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
- this->dataGridView1->ColumnHeadersVisible = false;
- this->dataGridView1->GridColor = System::Drawing::SystemColors::Control;
- this->dataGridView1->Location = System::Drawing::Point(73, 136);
- this->dataGridView1->Name = L"dataGridView1";
- this->dataGridView1->RowHeadersVisible = false;
- this->dataGridView1->RowHeadersWidth = 30;
- this->dataGridView1->RowTemplate->Height = 24;
- this->dataGridView1->Size = System::Drawing::Size(375, 392);
- this->dataGridView1->TabIndex = 1;
- this->dataGridView1->CellContentClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &MyForm::dataGridView1_CellContentClick);
- //
- // textBox1
- //
- this->textBox1->BackColor = System::Drawing::SystemColors::InactiveBorder;
- this->textBox1->ForeColor = System::Drawing::SystemColors::InfoText;
- this->textBox1->Location = System::Drawing::Point(260, 46);
- this->textBox1->Name = L"textBox1";
- this->textBox1->Size = System::Drawing::Size(65, 22);
- this->textBox1->TabIndex = 2;
- this->textBox1->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox1_TextChanged);
- this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox1_KeyPress);
- //
- // textBox2
- //
- this->textBox2->BackColor = System::Drawing::SystemColors::InactiveBorder;
- this->textBox2->ForeColor = System::Drawing::SystemColors::InfoText;
- this->textBox2->Location = System::Drawing::Point(260, 73);
- this->textBox2->Name = L"textBox2";
- this->textBox2->Size = System::Drawing::Size(65, 22);
- this->textBox2->TabIndex = 3;
- this->textBox2->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox2_TextChanged);
- this->textBox2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox2_KeyPress);
- //
- // button1
- //
- this->button1->BackColor = System::Drawing::Color::Gainsboro;
- this->button1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::None;
- this->button1->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
- this->button1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button1.Image")));
- this->button1->Location = System::Drawing::Point(331, 34);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(85, 73);
- this->button1->TabIndex = 4;
- this->button1->TabStop = false;
- this->button1->UseVisualStyleBackColor = false;
- this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(80, 48);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(179, 17);
- this->label1->TabIndex = 5;
- this->label1->Text = L"Введите кол-во столбцов:";
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Location = System::Drawing::Point(80, 75);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(155, 17);
- this->label2->TabIndex = 6;
- this->label2->Text = L"Введите кол-во строк:";
- //
- // label3
- //
- this->label3->AutoSize = true;
- this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7.8F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->label3->ForeColor = System::Drawing::Color::Black;
- this->label3->Location = System::Drawing::Point(80, 12);
- this->label3->Name = L"label3";
- this->label3->Size = System::Drawing::Size(458, 17);
- this->label3->TabIndex = 7;
- this->label3->Text = L"[INFO] Заполните поля и нажмите кнопку для построения матрицы.";
- //
- // label4
- //
- this->label4->AutoSize = true;
- this->label4->ForeColor = System::Drawing::SystemColors::ControlDark;
- this->label4->Location = System::Drawing::Point(853, 497);
- this->label4->Name = L"label4";
- this->label4->Size = System::Drawing::Size(62, 34);
- this->label4->TabIndex = 8;
- this->label4->Text = L"made in rnDIIT";
- this->label4->TextAlign = System::Drawing::ContentAlignment::TopCenter;
- //
- // label5
- //
- this->label5->AutoSize = true;
- this->label5->Location = System::Drawing::Point(80, 109);
- this->label5->Name = L"label5";
- this->label5->Size = System::Drawing::Size(391, 17);
- this->label5->TabIndex = 9;
- this->label5->Text = L"[INFO] После нажатия на кнопку заполните массив ниже. ";
- //
- // label6
- //
- this->label6->AutoSize = true;
- this->label6->Location = System::Drawing::Point(640, 11);
- this->label6->Name = L"label6";
- this->label6->Size = System::Drawing::Size(180, 34);
- this->label6->TabIndex = 10;
- this->label6->Text = L"Нажмите на эту кнопку rnдля выполнения задания.";
- this->label6->TextAlign = System::Drawing::ContentAlignment::TopCenter;
- //
- // button2
- //
- this->button2->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button2.Image")));
- this->button2->Location = System::Drawing::Point(685, 53);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(85, 73);
- this->button2->TabIndex = 11;
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click_1);
- //
- // dataGridView2
- //
- this->dataGridView2->BackgroundColor = System::Drawing::SystemColors::Control;
- this->dataGridView2->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
- this->dataGridView2->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
- this->dataGridView2->GridColor = System::Drawing::SystemColors::Control;
- this->dataGridView2->Location = System::Drawing::Point(472, 136);
- this->dataGridView2->Name = L"dataGridView2";
- this->dataGridView2->RowTemplate->Height = 24;
- this->dataGridView2->Size = System::Drawing::Size(375, 392);
- this->dataGridView2->TabIndex = 12;
- this->dataGridView2->CellContentClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &MyForm::dataGridView2_CellContentClick);
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->BackColor = System::Drawing::Color::Gainsboro;
- this->ClientSize = System::Drawing::Size(921, 540);
- this->Controls->Add(this->dataGridView2);
- this->Controls->Add(this->button2);
- this->Controls->Add(this->label6);
- this->Controls->Add(this->label5);
- this->Controls->Add(this->label4);
- this->Controls->Add(this->label3);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->button1);
- this->Controls->Add(this->textBox2);
- this->Controls->Add(this->textBox1);
- this->Controls->Add(this->dataGridView1);
- this->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
- this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
- this->MaximizeBox = false;
- this->Name = L"MyForm";
- this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
- this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView2))->EndInit();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- dataGridView1->Columns->Clear();
- dataGridView1->Rows->Clear();
- dataGridView2->Columns->Clear();
- dataGridView2->Rows->Clear();
- if (textBox1->Text->Length != 0) {
- dataGridView1->ColumnCount = Convert::ToInt32(textBox1->Text);
- dataGridView1->RowCount = Convert::ToInt32(textBox2->Text);
- matrix.rows = Convert::ToInt32(textBox2->Text);
- matrix.columns = Convert::ToInt32(textBox2->Text);
- // выделение памяти
- matrix.ptr = new int*[matrix.rows];
- for (int i = 0; i < matrix.rows; i++)
- matrix.ptr[i] = new int[matrix.columns];
- // заполнение матрицы
- for (int i = 0; i < matrix.rows; i++) {
- for (int j = 0; j < matrix.columns; j++)
- matrix.ptr[i][j] = rand() % 21 + (-10);
- }
- for (int i = 0; i < matrix.rows; i++) {
- for (int j = 0; j < matrix.rows; j++) {
- dataGridView1->Rows[i]->Cells[j]->Value = matrix.ptr[i][j];
- }
- }
- /*dataGridView1->Columns[0]->Width = 50;
- dataGridView1->Columns[1]->Width = 50;
- dataGridView1->Columns[2]->Width = 50;
- dataGridView1->Columns[3]->Width = 50;*/
- }
- }
- private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
- char number = e->KeyChar;
- if ((e->KeyChar <= 47 || e->KeyChar >= 58) && number != 8 && number != 44 && number != 46 && number != 45) //цифры, клавиша BackSpace и запятая а ASCII
- {
- e->Handled = true;
- MessageBox::Show("Вводить можно только цифры, а также символы . , - ");
- }
- }
- private: System::Void textBox2_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
- char number = e->KeyChar;
- if ((e->KeyChar <= 47 || e->KeyChar >= 58) && number != 8 && number != 44 && number != 46 && number != 45) //цифры, клавиша BackSpace и запятая а ASCII
- {
- e->Handled = true;
- MessageBox::Show("Вводить можно только цифры, а также символы . , - ");
- }
- }
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void button2_Click_1(System::Object^ sender, System::EventArgs^ e) {
- int *chislo = new int[matrix.columns];
- for (int j = 0; j < matrix.columns; j++) {
- chislo[j] = 0;
- }
- // Проверка на подходимость и занесение подходящих чисел в массив chislo
- for (int i = 0; i < matrix.rows; i++) {
- for (int j = 0; j < matrix.columns; j++) {
- if (matrix.ptr[i][j] % 2 == -1) {
- chislo[j] += matrix.ptr[i][j];
- }
- else {
- chislo[j] += 0;
- }
- }
- }
- for (int i = 1; i < matrix.columns; ++i) {
- size_t smallest_stolb = matrix.columns - i;
- // находим самый маленькую характеристику столбов
- for (int j = 0; j < matrix.columns - i; j++)
- if (chislo[j] < chislo[smallest_stolb])
- smallest_stolb = j;
- // столбы меняем, и их характеристику
- for (int j = 0; j < matrix.rows; j++) {
- int tmp = matrix.ptr[j][matrix.columns - i];
- matrix.ptr[j][matrix.columns - i] = matrix.ptr[j][smallest_stolb];
- matrix.ptr[j][smallest_stolb] = tmp;
- }
- { int temp = chislo[matrix.columns - i];
- chislo[matrix.columns - i] = chislo[smallest_stolb];
- chislo[smallest_stolb] = temp; }
- }
- // Проверял такой массив:
- // -3 -5 1 0
- // 1 -3 -1 0
- // -2 3 0 0
- for (int i = 0; i < matrix.rows; i++) {
- for (int j = 0; j < matrix.columns; j++) {
- dataGridView2[j, i]->Value = matrix.ptr[i][j];
- }
- }
- }
- private: System::Void dataGridView1_CellContentClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
- }
- private: System::Void dataGridView2_CellContentClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
- }
- private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e) {
- }
- };
- }
- #include "MyForm.h"
- using namespace System;
- using namespace System::Windows::Forms;
- [STAThreadAttribute]
- void Main(array<String^>^ args) {
- Application::EnableVisualStyles();
- Application::SetCompatibleTextRenderingDefault(false);
- Engineering6::MyForm form;
- Application::Run(%form);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement