Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include "MyForm1.h"
- #include <iostream>
- #pragma once
- namespace Project7 {
- 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::Button^ button1;
- protected:
- private: System::Windows::Forms::Button^ button5;
- private: System::Windows::Forms::Button^ button4;
- private: System::Windows::Forms::Button^ button3;
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::Button^ button0;
- private: System::Windows::Forms::Button^ buttonZnak;
- private: System::Windows::Forms::Button^ buttonDot;
- private: System::Windows::Forms::Button^ buttonRavno;
- private: System::Windows::Forms::Button^ buttonClear;
- private: System::Windows::Forms::Button^ buttonBackSpace;
- private: System::Windows::Forms::TextBox^ tb10;
- private: System::Windows::Forms::TextBox^ tb6;
- private: System::Windows::Forms::MenuStrip^ menuStrip1;
- private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ closeALLToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Label^ label2;
- private:
- /// <summary>
- /// Обязательная переменная конструктора.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Требуемый метод для поддержки конструктора — не изменяйте
- /// содержимое этого метода с помощью редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->button0 = (gcnew System::Windows::Forms::Button());
- this->button3 = (gcnew System::Windows::Forms::Button());
- this->button4 = (gcnew System::Windows::Forms::Button());
- this->button5 = (gcnew System::Windows::Forms::Button());
- this->buttonZnak = (gcnew System::Windows::Forms::Button());
- this->buttonDot = (gcnew System::Windows::Forms::Button());
- this->buttonRavno = (gcnew System::Windows::Forms::Button());
- this->buttonClear = (gcnew System::Windows::Forms::Button());
- this->buttonBackSpace = (gcnew System::Windows::Forms::Button());
- this->tb10 = (gcnew System::Windows::Forms::TextBox());
- this->tb6 = (gcnew System::Windows::Forms::TextBox());
- this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
- this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->closeALLToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->menuStrip1->SuspendLayout();
- this->SuspendLayout();
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(78, 160);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(60, 40);
- this->button1->TabIndex = 0;
- this->button1->Text = L"1";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
- //
- // button2
- //
- this->button2->Location = System::Drawing::Point(144, 160);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(60, 40);
- this->button2->TabIndex = 0;
- this->button2->Text = L"2";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
- //
- // button3
- //
- this->button3->Location = System::Drawing::Point(12, 210);
- this->button3->Name = L"button3";
- this->button3->Size = System::Drawing::Size(60, 40);
- this->button3->TabIndex = 0;
- this->button3->Text = L"3";
- this->button3->UseVisualStyleBackColor = true;
- this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
- //
- // button4
- //
- this->button4->Location = System::Drawing::Point(78, 210);
- this->button4->Name = L"button4";
- this->button4->Size = System::Drawing::Size(60, 40);
- this->button4->TabIndex = 0;
- this->button4->Text = L"4";
- this->button4->UseVisualStyleBackColor = true;
- this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
- //
- // button5
- //
- this->button5->Location = System::Drawing::Point(144, 210);
- this->button5->Name = L"button5";
- this->button5->Size = System::Drawing::Size(60, 40);
- this->button5->TabIndex = 0;
- this->button5->Text = L"5";
- this->button5->UseVisualStyleBackColor = true;
- this->button5->Click += gcnew System::EventHandler(this, &MyForm::button5_Click);
- //
- // button0
- //
- this->button0->Location = System::Drawing::Point(12, 160);
- this->button0->Name = L"button0";
- this->button0->Size = System::Drawing::Size(60, 40);
- this->button0->TabIndex = 0;
- this->button0->Text = L"0";
- this->button0->UseVisualStyleBackColor = true;
- this->button0->Click += gcnew System::EventHandler(this, &MyForm::button0_Click);
- //
- // buttonZnak
- //
- this->buttonZnak->Location = System::Drawing::Point(78, 300);
- this->buttonZnak->Name = L"buttonZnak";
- this->buttonZnak->Size = System::Drawing::Size(60, 40);
- this->buttonZnak->TabIndex = 0;
- this->buttonZnak->Text = L"+/-";
- this->buttonZnak->UseVisualStyleBackColor = true;
- this->buttonZnak->Click += gcnew System::EventHandler(this, &MyForm::buttonZnak_Click);
- //
- // buttonDot
- //
- this->buttonDot->Location = System::Drawing::Point(144, 300);
- this->buttonDot->Name = L"buttonDot";
- this->buttonDot->Size = System::Drawing::Size(60, 40);
- this->buttonDot->TabIndex = 0;
- this->buttonDot->Text = L".";
- this->buttonDot->UseVisualStyleBackColor = true;
- this->buttonDot->Click += gcnew System::EventHandler(this, &MyForm::buttonDot_Click);
- //
- // buttonRavno
- //
- this->buttonRavno->Location = System::Drawing::Point(226, 254);
- this->buttonRavno->Name = L"buttonRavno";
- this->buttonRavno->Size = System::Drawing::Size(190, 86);
- this->buttonRavno->TabIndex = 0;
- this->buttonRavno->Text = L"=";
- this->buttonRavno->UseVisualStyleBackColor = true;
- this->buttonRavno->Click += gcnew System::EventHandler(this, &MyForm::buttonRavno_Click);
- //
- // buttonClear
- //
- this->buttonClear->Location = System::Drawing::Point(226, 208);
- this->buttonClear->Name = L"buttonClear";
- this->buttonClear->Size = System::Drawing::Size(190, 40);
- this->buttonClear->TabIndex = 0;
- this->buttonClear->Text = L"Clear";
- this->buttonClear->UseVisualStyleBackColor = true;
- this->buttonClear->Click += gcnew System::EventHandler(this, &MyForm::buttonClear_Click);
- //
- // buttonBackSpace
- //
- this->buttonBackSpace->Location = System::Drawing::Point(225, 162);
- this->buttonBackSpace->Name = L"buttonBackSpace";
- this->buttonBackSpace->Size = System::Drawing::Size(190, 40);
- this->buttonBackSpace->TabIndex = 0;
- this->buttonBackSpace->Text = L"BackSpace";
- this->buttonBackSpace->UseVisualStyleBackColor = true;
- this->buttonBackSpace->Click += gcnew System::EventHandler(this, &MyForm::buttonBackSpace_Click);
- //
- // tb10
- //
- this->tb10->BackColor = System::Drawing::Color::White;
- this->tb10->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->tb10->Location = System::Drawing::Point(13, 116);
- this->tb10->Name = L"tb10";
- this->tb10->ReadOnly = true;
- this->tb10->Size = System::Drawing::Size(400, 38);
- this->tb10->TabIndex = 1;
- this->tb10->Text = L"0";
- this->tb10->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
- //
- // tb6
- //
- this->tb6->BackColor = System::Drawing::Color::White;
- this->tb6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->tb6->Location = System::Drawing::Point(12, 57);
- this->tb6->Name = L"tb6";
- this->tb6->ReadOnly = true;
- this->tb6->Size = System::Drawing::Size(400, 38);
- this->tb6->TabIndex = 1;
- this->tb6->Text = L"0";
- this->tb6->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
- //
- // menuStrip1
- //
- this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
- this->fileToolStripMenuItem,
- this->helpToolStripMenuItem
- });
- this->menuStrip1->Location = System::Drawing::Point(0, 0);
- this->menuStrip1->Name = L"menuStrip1";
- this->menuStrip1->Size = System::Drawing::Size(356, 24);
- this->menuStrip1->TabIndex = 2;
- this->menuStrip1->Text = L"menuStrip1";
- //
- // fileToolStripMenuItem
- //
- this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->closeALLToolStripMenuItem });
- this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
- this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
- this->fileToolStripMenuItem->Text = L"File";
- //
- // closeALLToolStripMenuItem
- //
- this->closeALLToolStripMenuItem->Name = L"closeALLToolStripMenuItem";
- this->closeALLToolStripMenuItem->Size = System::Drawing::Size(126, 22);
- this->closeALLToolStripMenuItem->Text = L"Close ALL";
- this->closeALLToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::closeALLToolStripMenuItem_Click);
- //
- // helpToolStripMenuItem
- //
- this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem";
- this->helpToolStripMenuItem->Size = System::Drawing::Size(44, 20);
- this->helpToolStripMenuItem->Text = L"Help";
- this->helpToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::helpToolStripMenuItem_Click);
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(13, 96);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(159, 13);
- this->label1->TabIndex = 3;
- this->label1->Text = L"Десятеричная система счисления";
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Location = System::Drawing::Point(10, 37);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(159, 13);
- this->label2->TabIndex = 3;
- this->label2->Text = L"Шестеричная система счисления";
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(646, 638);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->tb6);
- this->Controls->Add(this->tb10);
- this->Controls->Add(this->button0);
- this->Controls->Add(this->buttonBackSpace);
- this->Controls->Add(this->buttonClear);
- this->Controls->Add(this->buttonRavno);
- this->Controls->Add(this->button2);
- this->Controls->Add(this->button3);
- this->Controls->Add(this->button4);
- this->Controls->Add(this->button5);
- this->Controls->Add(this->buttonDot);
- this->Controls->Add(this->buttonZnak);
- this->Controls->Add(this->button1);
- this->Controls->Add(this->menuStrip1);
- this->MainMenuStrip = this->menuStrip1;
- this->MaximumSize = System::Drawing::Size(452, 400);
- this->MinimumSize = System::Drawing::Size(452, 400);
- this->Name = L"MyForm";
- this->Text = L"перевод из шестеричной в десятичную сс";
- this->menuStrip1->ResumeLayout(false);
- this->menuStrip1->PerformLayout();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- long long n = 0; // Количество цифр в числе.
- String^ vivod = {}; // Строка для запоминания содержимого поля вывода (на случай изменения поля вывода при переполнении)
- #pragma endregion
- String^ ost(String^ x, long long y) { // Перевод дробной части
- double eps = pow(10, -19);
- double ost = Convert::ToDouble(x); // Перевод строки
- ost -= floor(ost); // Создание строки для вывода ответа
- double o = (double)1 / 6; // переменная для записи целой части числа в цикле
- double res = 0;
- long long whole = 0;
- while (ost != 0 && y != 19) {
- ost *= 10;
- whole = floor(ost);
- ost -= whole;
- res += whole * o;
- o /= 6;
- y++;
- }
- return Convert::ToString(res); // Возвращение переведённой строки
- std::cout << res;
- }
- String^ cel(String^ x) {
- if (x == "0") return "0"; // проверка на 0
- _int64 chislo = Convert::ToInt64(x); // отбрасывание дробной части исходного числа
- long long num = 0; // Переменная для записи остатка
- long long degree = 0;
- while (chislo != 0) {
- num += (chislo % 10) * pow(6, degree);
- chislo /= 10;
- degree++;
- }
- return Convert::ToString(num);
- }
- void zapis(long long x) // Ввод данных в верхний текстбокс.
- {
- if (n != 12)
- {
- if (tb6->Text == "0" || tb6->Text == "-0")
- {
- if (x != 0)
- {
- if (tb6->Text == "0") tb6->Text = Convert::ToString(x);
- if (tb6->Text == "-0") tb6->Text = "-" + Convert::ToString(x);
- n++;
- }
- }
- else
- {
- tb6->Text += x;
- n++;
- }
- if (n == 12)
- {
- vivod = tb10->Text;
- tb10->Text = "Максимум символов";
- }
- }
- }
- private: System::Void closeALLToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- //Функция закрытия программы
- this->Close();
- }
- /*
- buttonX_Click - функции нажатия на кнопки 0-5, отправляют введённую цифру в zapis
- */
- private: System::Void button0_Click(System::Object^ sender, System::EventArgs^ e) {
- zapis(0);
- }
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- zapis(1);
- }
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- zapis(2);
- }
- private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
- zapis(3);
- }
- private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
- zapis(4);
- }
- private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
- zapis(5);
- }
- private: System::Void buttonClear_Click(System::Object^ sender, System::EventArgs^ e) {
- // Очистка полей ввода, вывода, счётчика введённых цифр
- tb6->Text = "0";
- tb10->Text = "0";
- n = 0;
- }
- private: System::Void buttonDot_Click(System::Object^ sender, System::EventArgs^ e) {
- // Нажатие на кнопку разделителя
- if (tb6->Text->Contains(".") == 0) // Проверка на наличие разделителя
- {
- if (tb6->Text == "0" || tb6->Text == "-0") n++; // если в целой части 0 или -0, считаем 0 как цифру.
- tb6->Text = tb6->Text + "."; // Дописываем разделитель справа
- }
- }
- private: System::Void buttonZnak_Click(System::Object^ sender, System::EventArgs^ e) {
- // Нажатие на кнопку "+/-"
- if (tb6->Text->Contains("-") == 0) tb6->Text = "-" + tb6->Text; // Если минуса не было, дописываем слева
- else
- {
- tb6->Text = tb6->Text->Replace("-", ""); // если минус был - меняем на пустоту (удаляем минус).
- }
- }
- private: System::Void buttonBackSpace_Click(System::Object^ sender, System::EventArgs^ e) {
- // Нажатие на кнопку BackSpace (Удаление последнего символа)
- bool dot = tb6->Text->Contains("."); // Проверка на разделитель
- if (n == 1 && dot == 0) // 1 цифра и разделителя нет
- {
- if (tb6->Text->Contains("-") == 1)
- {
- tb6->Text = "-" + "0";
- n--;
- }
- else
- {
- n--;
- tb6->Text = "0";
- }
- }
- if (n == 1 && dot == 1) // 1 цифра и есть разделитель
- {
- tb6->Text = tb6->Text->Remove(tb6->Text->Length - 1, 1);
- }
- if (n > 1) // цифр больше чем 1
- {
- tb6->Text = tb6->Text->Remove(tb6->Text->Length - 1, 1);
- if (dot == tb6->Text->Contains(".")) n--;
- }
- if (n == 11) tb10->Text = vivod; // Возвращение ответа в поле вывода, если там было сообщение о переполнении
- }
- private: System::Void buttonRavno_Click(System::Object^ sender, System::EventArgs^ e) {
- // кнопка "="
- bool minus = tb6->Text->Contains("-");
- if (tb6->Text->Contains(".") == 0)
- {
- if (minus == 0) tb10->Text = cel(tb6->Text->Replace("-", ""));
- else
- {
- tb10->Text = "-" + cel(tb6->Text->Replace("-", ""));
- }
- }
- else
- {
- _int64 celoe = _int64(Convert::ToDouble(tb6->Text));
- String^ a = tb6->Text; // новая строка с элементами текстбокса
- long long position = 0; // переменная для определения позиции разделителя
- long long size = tb6->Text->Length; // Количество символов в строке
- for (long long i = 0; i < size; i++) // цикл подсчёта позиции разделителя
- {
- if (a[i] == '.')
- {
- position = i;
- break;
- }
- }
- a = tb6->Text->Remove(0, position); // Удаление целой части при наличии остатка
- if (minus == 0)
- {
- tb10->Text = cel(Convert::ToString(celoe));
- long long y = tb10->Text->Length;
- y++;
- if (a != ".") tb10->Text += ost(a, y)->Remove(0, 1); // Проверка на наличие символов в дробной части.
- }
- else
- {
- tb10->Text = "-" + cel(Convert::ToString(celoe)->Replace("-", ""));
- long long y = tb10->Text->Length;
- if (a != ".") tb10->Text += ost(a, y)->Remove(0, 1);
- }
- }
- if (tb6->Text == "0") tb10->Text = "0";
- if (tb6->Text == "-0") tb10->Text = "-0";
- if (tb6->Text->Contains("-0") == 1 && tb6->Text->Contains("1") == 0 && tb6->Text->Contains("2") == 0 && tb6->Text->Contains("3") == 0 && tb6->Text->Contains("4") == 0 && tb6->Text->Contains("5") == 0) tb10->Text = "-0";
- vivod = tb10->Text;
- }
- private: System::Void helpToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- // Нажатие на "Help"
- MyForm1^ newForm = gcnew MyForm1; // создание формы справки
- newForm->ShowDialog(); // инициализация формы справки
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement