Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include "MyForm1.h"
- #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^ button2;
- private: System::Windows::Forms::Button^ button3;
- private: System::Windows::Forms::Button^ button4;
- private: System::Windows::Forms::Button^ button5;
- private: System::Windows::Forms::Button^ button6;
- private: System::Windows::Forms::Button^ button7;
- private: System::Windows::Forms::Button^ button8;
- private: System::Windows::Forms::Button^ button9;
- 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^ tb13;
- private: System::Windows::Forms::TextBox^ tb10;
- 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->button3 = (gcnew System::Windows::Forms::Button());
- this->button4 = (gcnew System::Windows::Forms::Button());
- this->button5 = (gcnew System::Windows::Forms::Button());
- this->button6 = (gcnew System::Windows::Forms::Button());
- this->button7 = (gcnew System::Windows::Forms::Button());
- this->button8 = (gcnew System::Windows::Forms::Button());
- this->button9 = (gcnew System::Windows::Forms::Button());
- this->button0 = (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->tb13 = (gcnew System::Windows::Forms::TextBox());
- this->tb10 = (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(12, 254);
- 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(78, 254);
- 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);
- //
- // button0
- //
- this->button0->Location = System::Drawing::Point(12, 300);
- 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(118, 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(118, 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(118, 40);
- this->buttonBackSpace->TabIndex = 0;
- this->buttonBackSpace->Text = L"BackSpace";
- this->buttonBackSpace->UseVisualStyleBackColor = true;
- this->buttonBackSpace->Click += gcnew System::EventHandler(this, &MyForm::buttonBackSpace_Click);
- //
- // tb13
- //
- this->tb13->BackColor = System::Drawing::Color::White;
- this->tb13->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->tb13->Location = System::Drawing::Point(13, 116);
- this->tb13->Name = L"tb13";
- this->tb13->ReadOnly = true;
- this->tb13->Size = System::Drawing::Size(331, 38);
- this->tb13->TabIndex = 1;
- this->tb13->Text = L"0";
- this->tb13->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
- //
- // 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(12, 57);
- this->tb10->Name = L"tb10";
- this->tb10->ReadOnly = true;
- this->tb10->Size = System::Drawing::Size(331, 38);
- this->tb10->TabIndex = 1;
- this->tb10->Text = L"0";
- this->tb10->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"13-ричная система счисления";
- //
- // 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"10-ричная система счисления";
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(356, 348);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->tb10);
- this->Controls->Add(this->tb13);
- this->Controls->Add(this->button0);
- this->Controls->Add(this->button7);
- this->Controls->Add(this->buttonBackSpace);
- this->Controls->Add(this->buttonClear);
- this->Controls->Add(this->buttonRavno);
- this->Controls->Add(this->button4);
- this->Controls->Add(this->button9);
- this->Controls->Add(this->button8);
- this->Controls->Add(this->button6);
- this->Controls->Add(this->button5);
- this->Controls->Add(this->button3);
- this->Controls->Add(this->button2);
- 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(372, 386);
- this->MinimumSize = System::Drawing::Size(372, 386);
- this->Name = L"MyForm";
- this->Text = L"Калькулятор 10->13";
- this->menuStrip1->ResumeLayout(false);
- this->menuStrip1->PerformLayout();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- int n = 0; // Количество цифр в числе.
- String^ vivod = {}; // Строка для запоминания содержимого поля вывода (на случай изменения поля вывода при переполнении)
- #pragma endregion
- String^ ost(String^ x, int y) { // Перевод дробной части
- double ost = Convert::ToDouble(x); // Перевод строки в дабл
- String^ otv = "0,"; // Создание строки для вывода ответа
- double o = 0; // переменная для записи целой части числа в цикле
- while (ost != 0 && y != 19) {
- ost *= 3; // Умножение исходного числа на 13
- ost = modf(ost, &o); // отделение целого и дробного. ost - дробное.
- if (o < 3) otv += Convert::ToString(o);
- y++;
- }
- return otv; // Возвращение переведённой строки
- }
- String^ cel(String^ x) {
- if(x=="0") return "0"; // проверка на 0
- String^ otv = ""; // Создание строки для вывода ответа
- _int64 chislo = Convert::ToInt64(x); // отбрасывание дробной части исходного числа
- int num = 0; // Переменная для записи остатка
- while (chislo != 0 ) {
- num = chislo % 3;
- chislo = chislo / 3;
- otv = Convert::ToString(num) + otv;
- }
- return otv;
- }
- void zapis(int x) // Ввод данных в верхний текстбокс.
- {
- if (n != 12)
- {
- if (tb10->Text == "0" || tb10->Text == "-0")
- {
- if (x != 0)
- {
- if (tb10->Text == "0") tb10->Text = Convert::ToString(x);
- if (tb10->Text == "-0") tb10->Text = "-" + Convert::ToString(x);
- n++;
- }
- }
- else
- {
- tb10->Text += x;
- n++;
- }
- if (n == 12)
- {
- vivod = tb13->Text;
- tb13->Text = "Максимум символов";
- }
- }
- }
- private: System::Void closeALLToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- //Функция закрытия программы
- this->Close();
- }
- /*
- buttonX_Click - функции нажатия на кнопки 1-9, отправляют введённую цифру в 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 buttonClear_Click(System::Object^ sender, System::EventArgs^ e) {
- // Очистка полей ввода, вывода, счётчика введённых цифр
- tb10->Text = "0";
- tb13->Text = "0";
- n = 0;
- }
- private: System::Void buttonDot_Click(System::Object^ sender, System::EventArgs^ e) {
- // Нажатие на кнопку разделителя
- if (tb10->Text->Contains(",") == 0) // Проверка на наличие разделителя
- {
- if (tb10->Text == "0" || tb10->Text == "-0") n++; // если в целой части 0 или -0, считаем 0 как цифру.
- tb10->Text = tb10->Text + ","; // Дописываем разделитель справа
- }
- }
- private: System::Void buttonZnak_Click(System::Object^ sender, System::EventArgs^ e) {
- // Нажатие на кнопку "+/-"
- if (tb10->Text->Contains("-") == 0) tb10->Text = "-" + tb10->Text; // Если минуса не было, дописываем слева
- else
- {
- tb10->Text = tb10->Text->Replace("-", ""); // если минус был - меняем на пустоту (удаляем минус).
- }
- }
- private: System::Void buttonBackSpace_Click(System::Object^ sender, System::EventArgs^ e) {
- // Нажатие на кнопку BackSpace (Удаление последнего символа)
- bool dot = tb10->Text->Contains(","); // Проверка на разделитель
- if (n == 1 && dot == 0) // 1 цифра и разделителя нет
- {
- if (tb10->Text->Contains("-") == 1)
- {
- tb10->Text = "-" + "0";
- n--;
- }
- else
- {
- n--;
- tb10->Text = "0";
- }
- }
- if (n == 1 && dot == 1) // 1 цифра и есть разделитель
- {
- tb10->Text = tb10->Text->Remove(tb10->Text->Length - 1, 1);
- }
- if (n > 1) // цифр больше чем 1
- {
- tb10->Text = tb10->Text->Remove(tb10->Text->Length - 1, 1);
- if(dot == tb10->Text->Contains(",")) n--;
- }
- if (n == 11) tb13->Text = vivod; // Возвращение ответа в поле вывода, если там было сообщение о переполнении
- }
- private: System::Void buttonRavno_Click(System::Object^ sender, System::EventArgs^ e) {
- // кнопка "="
- bool minus = tb10->Text->Contains("-");
- if (tb10->Text->Contains(",") == 0)
- {
- if(minus == 0) tb13->Text = cel(tb10->Text->Replace("-", ""));
- else
- {
- tb13->Text = "-" + cel(tb10->Text->Replace("-", ""));
- }
- }
- else
- {
- _int64 celoe = _int64(Convert::ToDouble(tb10->Text));
- String^ a = tb10->Text; // новая строка с элементами текстбокса
- int position = 0; // переменная для определения позиции разделителя
- int size = tb10->Text->Length; // Количество символов в строке
- for (int i = 0; i < size; i++) // цикл подсчёта позиции разделителя
- {
- if (a[i] == ',')
- {
- position = i;
- break;
- }
- }
- a = tb10->Text->Remove(0, position); // Удаление целой части при наличии остатка
- if (minus == 0)
- {
- tb13->Text = cel(Convert::ToString(celoe));
- int y = tb13->Text->Length;
- if (a != ",") tb13->Text += ost(a, y)->Remove(0, 1); // Проверка на наличие символов в дробной части.
- }
- else
- {
- tb13->Text = "-" + cel(Convert::ToString(celoe)->Replace("-", ""));
- int y = tb13->Text->Length;
- if (a != ",") tb13->Text += ost(a, y)->Remove(0, 1);
- }
- }
- if (tb10->Text == "0") tb13->Text = "0";
- if (tb10->Text == "-0") tb13->Text = "-0";
- vivod = tb13->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