Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <fstream>
- #include <msclr\marshal_cppstd.h>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <sstream>
- #include <atlstr.h>
- #include <filesystem>
- namespace BruteForceSort {
- using namespace std;
- 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;
- }
- }
- protected:
- private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::TabControl^ tabControl1;
- private: System::Windows::Forms::TabPage^ tabPage1;
- private: System::Windows::Forms::TabPage^ tabPage2;
- private: System::Windows::Forms::WebBrowser^ webBrowser1;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::Button^ button3;
- private: System::Windows::Forms::RichTextBox^ input_array;
- private:
- /// <summary>
- /// Обязательная переменная конструктора.
- /// </summary>
- System::ComponentModel::Container^ components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Требуемый метод для поддержки конструктора — не изменяйте
- /// содержимое этого метода с помощью редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
- this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
- this->button3 = (gcnew System::Windows::Forms::Button());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
- this->webBrowser1 = (gcnew System::Windows::Forms::WebBrowser());
- this->input_array = (gcnew System::Windows::Forms::RichTextBox());
- this->tabControl1->SuspendLayout();
- this->tabPage1->SuspendLayout();
- this->tabPage2->SuspendLayout();
- this->SuspendLayout();
- //
- // button2
- //
- this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->button2->Location = System::Drawing::Point(14, 159);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(389, 30);
- this->button2->TabIndex = 2;
- this->button2->Text = L"Из формы";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
- //
- // tabControl1
- //
- this->tabControl1->Controls->Add(this->tabPage1);
- this->tabControl1->Controls->Add(this->tabPage2);
- this->tabControl1->Location = System::Drawing::Point(7, 12);
- this->tabControl1->Name = L"tabControl1";
- this->tabControl1->SelectedIndex = 0;
- this->tabControl1->Size = System::Drawing::Size(419, 295);
- this->tabControl1->TabIndex = 4;
- //
- // tabPage1
- //
- this->tabPage1->BackColor = System::Drawing::Color::Snow;
- this->tabPage1->Controls->Add(this->input_array);
- this->tabPage1->Controls->Add(this->button3);
- this->tabPage1->Controls->Add(this->button1);
- this->tabPage1->Controls->Add(this->label1);
- this->tabPage1->Controls->Add(this->button2);
- this->tabPage1->Location = System::Drawing::Point(4, 22);
- this->tabPage1->Name = L"tabPage1";
- this->tabPage1->Padding = System::Windows::Forms::Padding(3);
- this->tabPage1->Size = System::Drawing::Size(411, 269);
- this->tabPage1->TabIndex = 0;
- this->tabPage1->Text = L"Ввод данных";
- //
- // button3
- //
- this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->button3->Location = System::Drawing::Point(14, 231);
- this->button3->Name = L"button3";
- this->button3->Size = System::Drawing::Size(389, 30);
- this->button3->TabIndex = 8;
- this->button3->Text = L"Выход";
- this->button3->UseVisualStyleBackColor = true;
- this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
- //
- // button1
- //
- this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->button1->Location = System::Drawing::Point(14, 195);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(389, 30);
- this->button1->TabIndex = 7;
- this->button1->Text = L"Из файла";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click_1);
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Font = (gcnew System::Drawing::Font(L"Candara", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label1->Location = System::Drawing::Point(135, 3);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(124, 23);
- this->label1->TabIndex = 5;
- this->label1->Text = L"Ввод массива";
- //
- // tabPage2
- //
- this->tabPage2->Controls->Add(this->webBrowser1);
- this->tabPage2->Location = System::Drawing::Point(4, 22);
- this->tabPage2->Name = L"tabPage2";
- this->tabPage2->Padding = System::Windows::Forms::Padding(3);
- this->tabPage2->Size = System::Drawing::Size(411, 269);
- this->tabPage2->TabIndex = 1;
- this->tabPage2->Text = L"Веб-браузер";
- this->tabPage2->UseVisualStyleBackColor = true;
- //
- // webBrowser1
- //
- this->webBrowser1->Location = System::Drawing::Point(8, 6);
- this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20);
- this->webBrowser1->Name = L"webBrowser1";
- this->webBrowser1->Size = System::Drawing::Size(401, 271);
- this->webBrowser1->TabIndex = 1;
- //
- // input_array
- //
- this->input_array->Location = System::Drawing::Point(42, 29);
- this->input_array->Name = L"input_array";
- this->input_array->Size = System::Drawing::Size(323, 96);
- this->input_array->TabIndex = 9;
- this->input_array->Text = L"";
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(432, 315);
- this->Controls->Add(this->tabControl1);
- this->Name = L"MyForm";
- this->Text = L"Сортировка методом перебора";
- this->tabControl1->ResumeLayout(false);
- this->tabPage1->ResumeLayout(false);
- this->tabPage1->PerformLayout();
- this->tabPage2->ResumeLayout(false);
- this->ResumeLayout(false);
- }
- #pragma endregion
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- OpenFileDialog^ opn = gcnew OpenFileDialog();
- opn->Filter = "Html files (*.html)|*.html|All files (*.*)|*.*";
- if (opn->ShowDialog() == Windows::Forms::DialogResult::OK) {
- webBrowser1->Navigate(opn->FileName);
- }
- }
- vector<std::string> split_by_delimiter(std::string input, char delimiter) {
- size_t pos = 0;
- std::string token;
- std::vector<std::string> output;
- while ((pos = input.find(delimiter)) != std::string::npos) {
- token = input.substr(0, pos);
- output.push_back(token);
- input.erase(0, pos + 1);
- }
- output.push_back(input);
- return output;
- }
- void controller(std::string str) {
- if (str == "") {
- MessageBox::Show("Введи данные в правильном формате!", "Ошибка ввода данных", MessageBoxButtons::OK, MessageBoxIcon::Error);
- return;
- }
- std::string file_name = "report.html";
- auto current_path = std::filesystem::current_path().string() + (string)"\\" + file_name;
- ofstream myfile;
- myfile.open(current_path);
- myfile << "<!DOCTYPE html><html><head></head><body>";
- myfile << "Сортировка массива методом перебора.<br>Массив до сортировки: <br>";
- vector<int> vec;
- int column_size = 0;
- vector<std::string> rows = split_by_delimiter(str, '\n');
- for (auto row : rows) {
- vector<std::string> columns = split_by_delimiter(row, ' ');
- column_size = columns.size();
- for (auto column : columns) {
- vec.push_back(std::stoi(column, nullptr, 10));
- myfile << column + " ";
- }
- myfile << "<br>";
- }
- int vecsize = vec.size();
- for (int j = 0; j < vecsize - 1; ++j) {
- int min = j;
- for (int i = j + 1; i < vecsize; ++i) {
- if (vec.at(min) > vec.at(i)) {
- min = i;
- }
- }
- if (min != j)
- swap(vec.at(j), vec.at(min));
- }
- myfile << "Массив после сортировки: <br> ";
- for (int i = 0; i < vec.size();) {
- myfile << std::to_string(vec[i]) + " ";
- if (!(++i % column_size)) myfile << "<br>";
- }
- myfile << "</body></html>" << std::endl;
- myfile.close();
- webBrowser1->Navigate(gcnew String(current_path.c_str()));
- this->tabControl1->SelectedIndex = 1;
- }
- public: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- controller(msclr::interop::marshal_as<std::string>(input_array->Text));
- }
- private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) {
- openFileDialog1->Title = "Открыть файл";
- openFileDialog1->Filter = "Text Files(*.txt)|*.txt|All files (*.*)|*.*";
- if (openFileDialog1->ShowDialog() == Windows::Forms::DialogResult::OK) {
- std::ifstream input(CString(openFileDialog1->FileName));
- std::stringstream sstr;
- while (input >> sstr.rdbuf());
- controller(sstr.str());
- input.close();
- }
- }
- private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
- exit(0);
- }
- private: System::Void input_array_TextChanged(System::Object^ sender, System::EventArgs^ e) {
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement