Advertisement
xxxdanilion

Untitled

Dec 16th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.93 KB | None | 0 0
  1. #include <cmath>
  2. #include "MyForm1.h"
  3. #include <iostream>
  4.  
  5.  
  6. #pragma once
  7.  
  8. namespace Project7 {
  9.  
  10. using namespace System;
  11. using namespace System::ComponentModel;
  12. using namespace System::Collections;
  13. using namespace System::Windows::Forms;
  14. using namespace System::Data;
  15. using namespace System::Drawing;
  16.  
  17. /// <summary>
  18. /// Сводка для MyForm
  19. /// </summary>
  20. public ref class MyForm : public System::Windows::Forms::Form
  21. {
  22. public:
  23. MyForm(void)
  24. {
  25. InitializeComponent();
  26. //
  27. //TODO: добавьте код конструктора
  28. //
  29. }
  30.  
  31. protected:
  32. /// <summary>
  33. /// Освободить все используемые ресурсы.
  34. /// </summary>
  35. ~MyForm()
  36. {
  37. if (components)
  38. {
  39. delete components;
  40. }
  41. }
  42. private: System::Windows::Forms::Button^ button1;
  43. protected:
  44. private: System::Windows::Forms::Button^ button5;
  45. private: System::Windows::Forms::Button^ button4;
  46. private: System::Windows::Forms::Button^ button3;
  47. private: System::Windows::Forms::Button^ button2;
  48. private: System::Windows::Forms::Button^ button0;
  49. private: System::Windows::Forms::Button^ buttonZnak;
  50. private: System::Windows::Forms::Button^ buttonDot;
  51. private: System::Windows::Forms::Button^ buttonRavno;
  52. private: System::Windows::Forms::Button^ buttonClear;
  53. private: System::Windows::Forms::Button^ buttonBackSpace;
  54. private: System::Windows::Forms::TextBox^ tb10;
  55. private: System::Windows::Forms::TextBox^ tb6;
  56. private: System::Windows::Forms::MenuStrip^ menuStrip1;
  57. private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
  58. private: System::Windows::Forms::ToolStripMenuItem^ closeALLToolStripMenuItem;
  59. private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem;
  60. private: System::Windows::Forms::Label^ label1;
  61. private: System::Windows::Forms::Label^ label2;
  62.  
  63. private:
  64. /// <summary>
  65. /// Обязательная переменная конструктора.
  66. /// </summary>
  67. System::ComponentModel::Container ^components;
  68.  
  69. #pragma region Windows Form Designer generated code
  70. /// <summary>
  71. /// Требуемый метод для поддержки конструктора — не изменяйте
  72. /// содержимое этого метода с помощью редактора кода.
  73. /// </summary>
  74. void InitializeComponent(void)
  75. {
  76. this->button1 = (gcnew System::Windows::Forms::Button());
  77. this->button2 = (gcnew System::Windows::Forms::Button());
  78. this->button0 = (gcnew System::Windows::Forms::Button());
  79. this->button3 = (gcnew System::Windows::Forms::Button());
  80. this->button4 = (gcnew System::Windows::Forms::Button());
  81. this->button5 = (gcnew System::Windows::Forms::Button());
  82. this->buttonZnak = (gcnew System::Windows::Forms::Button());
  83. this->buttonDot = (gcnew System::Windows::Forms::Button());
  84. this->buttonRavno = (gcnew System::Windows::Forms::Button());
  85. this->buttonClear = (gcnew System::Windows::Forms::Button());
  86. this->buttonBackSpace = (gcnew System::Windows::Forms::Button());
  87. this->tb10 = (gcnew System::Windows::Forms::TextBox());
  88. this->tb6 = (gcnew System::Windows::Forms::TextBox());
  89. this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
  90. this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  91. this->closeALLToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  92. this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  93. this->label1 = (gcnew System::Windows::Forms::Label());
  94. this->label2 = (gcnew System::Windows::Forms::Label());
  95. this->menuStrip1->SuspendLayout();
  96. this->SuspendLayout();
  97. //
  98. // button1
  99. //
  100. this->button1->Location = System::Drawing::Point(78, 160);
  101. this->button1->Name = L"button1";
  102. this->button1->Size = System::Drawing::Size(60, 40);
  103. this->button1->TabIndex = 0;
  104. this->button1->Text = L"1";
  105. this->button1->UseVisualStyleBackColor = true;
  106. this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  107. //
  108. // button2
  109. //
  110. this->button2->Location = System::Drawing::Point(144, 160);
  111. this->button2->Name = L"button2";
  112. this->button2->Size = System::Drawing::Size(60, 40);
  113. this->button2->TabIndex = 0;
  114. this->button2->Text = L"2";
  115. this->button2->UseVisualStyleBackColor = true;
  116. this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
  117. //
  118. // button3
  119. //
  120. this->button3->Location = System::Drawing::Point(12, 210);
  121. this->button3->Name = L"button3";
  122. this->button3->Size = System::Drawing::Size(60, 40);
  123. this->button3->TabIndex = 0;
  124. this->button3->Text = L"3";
  125. this->button3->UseVisualStyleBackColor = true;
  126. this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
  127. //
  128. // button4
  129. //
  130. this->button4->Location = System::Drawing::Point(78, 210);
  131. this->button4->Name = L"button4";
  132. this->button4->Size = System::Drawing::Size(60, 40);
  133. this->button4->TabIndex = 0;
  134. this->button4->Text = L"4";
  135. this->button4->UseVisualStyleBackColor = true;
  136. this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
  137. //
  138. // button5
  139. //
  140. this->button5->Location = System::Drawing::Point(144, 210);
  141. this->button5->Name = L"button5";
  142. this->button5->Size = System::Drawing::Size(60, 40);
  143. this->button5->TabIndex = 0;
  144. this->button5->Text = L"5";
  145. this->button5->UseVisualStyleBackColor = true;
  146. this->button5->Click += gcnew System::EventHandler(this, &MyForm::button5_Click);
  147. //
  148. // button0
  149. //
  150. this->button0->Location = System::Drawing::Point(12, 160);
  151. this->button0->Name = L"button0";
  152. this->button0->Size = System::Drawing::Size(60, 40);
  153. this->button0->TabIndex = 0;
  154. this->button0->Text = L"0";
  155. this->button0->UseVisualStyleBackColor = true;
  156. this->button0->Click += gcnew System::EventHandler(this, &MyForm::button0_Click);
  157. //
  158. // buttonZnak
  159. //
  160. this->buttonZnak->Location = System::Drawing::Point(78, 300);
  161. this->buttonZnak->Name = L"buttonZnak";
  162. this->buttonZnak->Size = System::Drawing::Size(60, 40);
  163. this->buttonZnak->TabIndex = 0;
  164. this->buttonZnak->Text = L"+/-";
  165. this->buttonZnak->UseVisualStyleBackColor = true;
  166. this->buttonZnak->Click += gcnew System::EventHandler(this, &MyForm::buttonZnak_Click);
  167. //
  168. // buttonDot
  169. //
  170. this->buttonDot->Location = System::Drawing::Point(144, 300);
  171. this->buttonDot->Name = L"buttonDot";
  172. this->buttonDot->Size = System::Drawing::Size(60, 40);
  173. this->buttonDot->TabIndex = 0;
  174. this->buttonDot->Text = L".";
  175. this->buttonDot->UseVisualStyleBackColor = true;
  176. this->buttonDot->Click += gcnew System::EventHandler(this, &MyForm::buttonDot_Click);
  177. //
  178. // buttonRavno
  179. //
  180. this->buttonRavno->Location = System::Drawing::Point(226, 254);
  181. this->buttonRavno->Name = L"buttonRavno";
  182. this->buttonRavno->Size = System::Drawing::Size(190, 86);
  183. this->buttonRavno->TabIndex = 0;
  184. this->buttonRavno->Text = L"=";
  185. this->buttonRavno->UseVisualStyleBackColor = true;
  186. this->buttonRavno->Click += gcnew System::EventHandler(this, &MyForm::buttonRavno_Click);
  187. //
  188. // buttonClear
  189. //
  190. this->buttonClear->Location = System::Drawing::Point(226, 208);
  191. this->buttonClear->Name = L"buttonClear";
  192. this->buttonClear->Size = System::Drawing::Size(190, 40);
  193. this->buttonClear->TabIndex = 0;
  194. this->buttonClear->Text = L"Clear";
  195. this->buttonClear->UseVisualStyleBackColor = true;
  196. this->buttonClear->Click += gcnew System::EventHandler(this, &MyForm::buttonClear_Click);
  197. //
  198. // buttonBackSpace
  199. //
  200. this->buttonBackSpace->Location = System::Drawing::Point(225, 162);
  201. this->buttonBackSpace->Name = L"buttonBackSpace";
  202. this->buttonBackSpace->Size = System::Drawing::Size(190, 40);
  203. this->buttonBackSpace->TabIndex = 0;
  204. this->buttonBackSpace->Text = L"BackSpace";
  205. this->buttonBackSpace->UseVisualStyleBackColor = true;
  206. this->buttonBackSpace->Click += gcnew System::EventHandler(this, &MyForm::buttonBackSpace_Click);
  207. //
  208. // tb10
  209. //
  210. this->tb10->BackColor = System::Drawing::Color::White;
  211. this->tb10->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  212. static_cast<System::Byte>(204)));
  213. this->tb10->Location = System::Drawing::Point(13, 116);
  214. this->tb10->Name = L"tb10";
  215. this->tb10->ReadOnly = true;
  216. this->tb10->Size = System::Drawing::Size(400, 38);
  217. this->tb10->TabIndex = 1;
  218. this->tb10->Text = L"0";
  219. this->tb10->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
  220. //
  221. // tb6
  222. //
  223. this->tb6->BackColor = System::Drawing::Color::White;
  224. this->tb6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  225. static_cast<System::Byte>(204)));
  226. this->tb6->Location = System::Drawing::Point(12, 57);
  227. this->tb6->Name = L"tb6";
  228. this->tb6->ReadOnly = true;
  229. this->tb6->Size = System::Drawing::Size(400, 38);
  230. this->tb6->TabIndex = 1;
  231. this->tb6->Text = L"0";
  232. this->tb6->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
  233. //
  234. // menuStrip1
  235. //
  236. this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
  237. this->fileToolStripMenuItem,
  238. this->helpToolStripMenuItem
  239. });
  240. this->menuStrip1->Location = System::Drawing::Point(0, 0);
  241. this->menuStrip1->Name = L"menuStrip1";
  242. this->menuStrip1->Size = System::Drawing::Size(356, 24);
  243. this->menuStrip1->TabIndex = 2;
  244. this->menuStrip1->Text = L"menuStrip1";
  245. //
  246. // fileToolStripMenuItem
  247. //
  248. this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->closeALLToolStripMenuItem });
  249. this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
  250. this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
  251. this->fileToolStripMenuItem->Text = L"File";
  252. //
  253. // closeALLToolStripMenuItem
  254. //
  255. this->closeALLToolStripMenuItem->Name = L"closeALLToolStripMenuItem";
  256. this->closeALLToolStripMenuItem->Size = System::Drawing::Size(126, 22);
  257. this->closeALLToolStripMenuItem->Text = L"Close ALL";
  258. this->closeALLToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::closeALLToolStripMenuItem_Click);
  259. //
  260. // helpToolStripMenuItem
  261. //
  262. this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem";
  263. this->helpToolStripMenuItem->Size = System::Drawing::Size(44, 20);
  264. this->helpToolStripMenuItem->Text = L"Help";
  265. this->helpToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::helpToolStripMenuItem_Click);
  266. //
  267. // label1
  268. //
  269. this->label1->AutoSize = true;
  270. this->label1->Location = System::Drawing::Point(13, 96);
  271. this->label1->Name = L"label1";
  272. this->label1->Size = System::Drawing::Size(159, 13);
  273. this->label1->TabIndex = 3;
  274. this->label1->Text = L"Десятеричная система счисления";
  275. //
  276. // label2
  277. //
  278. this->label2->AutoSize = true;
  279. this->label2->Location = System::Drawing::Point(10, 37);
  280. this->label2->Name = L"label2";
  281. this->label2->Size = System::Drawing::Size(159, 13);
  282. this->label2->TabIndex = 3;
  283. this->label2->Text = L"Шестеричная система счисления";
  284. //
  285. // MyForm
  286. //
  287. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  288. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  289. this->ClientSize = System::Drawing::Size(646, 638);
  290. this->Controls->Add(this->label2);
  291. this->Controls->Add(this->label1);
  292. this->Controls->Add(this->tb6);
  293. this->Controls->Add(this->tb10);
  294. this->Controls->Add(this->button0);
  295. this->Controls->Add(this->buttonBackSpace);
  296. this->Controls->Add(this->buttonClear);
  297. this->Controls->Add(this->buttonRavno);
  298. this->Controls->Add(this->button2);
  299. this->Controls->Add(this->button3);
  300. this->Controls->Add(this->button4);
  301. this->Controls->Add(this->button5);
  302. this->Controls->Add(this->buttonDot);
  303. this->Controls->Add(this->buttonZnak);
  304. this->Controls->Add(this->button1);
  305. this->Controls->Add(this->menuStrip1);
  306. this->MainMenuStrip = this->menuStrip1;
  307. this->MaximumSize = System::Drawing::Size(452, 400);
  308. this->MinimumSize = System::Drawing::Size(452, 400);
  309. this->Name = L"MyForm";
  310. this->Text = L"перевод из шестеричной в десятичную сс";
  311. this->menuStrip1->ResumeLayout(false);
  312. this->menuStrip1->PerformLayout();
  313. this->ResumeLayout(false);
  314. this->PerformLayout();
  315.  
  316. }
  317. long long n = 0; // Количество цифр в числе.
  318. String^ vivod = {}; // Строка для запоминания содержимого поля вывода (на случай изменения поля вывода при переполнении)
  319.  
  320. #pragma endregion
  321. String^ ost(String^ x, long long y) { // Перевод дробной части
  322. double eps = pow(10, -19);
  323. double ost = Convert::ToDouble(x); // Перевод строки
  324. ost -= floor(ost); // Создание строки для вывода ответа
  325. double o = (double)1 / 6; // переменная для записи целой части числа в цикле
  326. double res = 0;
  327. long long whole = 0;
  328. while (ost != 0 && y != 19) {
  329. ost *= 10;
  330. whole = floor(ost);
  331. ost -= whole;
  332. res += whole * o;
  333. o /= 6;
  334. y++;
  335. }
  336. return Convert::ToString(res); // Возвращение переведённой строки
  337. std::cout << res;
  338. }
  339. String^ cel(String^ x) {
  340. if (x == "0") return "0"; // проверка на 0
  341. _int64 chislo = Convert::ToInt64(x); // отбрасывание дробной части исходного числа
  342. long long num = 0; // Переменная для записи остатка
  343. long long degree = 0;
  344. while (chislo != 0) {
  345. num += (chislo % 10) * pow(6, degree);
  346. chislo /= 10;
  347. degree++;
  348. }
  349. return Convert::ToString(num);
  350. }
  351. void zapis(long long x) // Ввод данных в верхний текстбокс.
  352. {
  353. if (n != 12)
  354. {
  355. if (tb6->Text == "0" || tb6->Text == "-0")
  356. {
  357. if (x != 0)
  358. {
  359. if (tb6->Text == "0") tb6->Text = Convert::ToString(x);
  360. if (tb6->Text == "-0") tb6->Text = "-" + Convert::ToString(x);
  361. n++;
  362. }
  363. }
  364. else
  365. {
  366. tb6->Text += x;
  367. n++;
  368. }
  369. if (n == 12)
  370. {
  371. vivod = tb10->Text;
  372. tb10->Text = "Максимум символов";
  373. }
  374. }
  375. }
  376. private: System::Void closeALLToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  377. //Функция закрытия программы
  378. this->Close();
  379. }
  380. /*
  381. buttonX_Click - функции нажатия на кнопки 0-5, отправляют введённую цифру в zapis
  382. */
  383.  
  384. private: System::Void button0_Click(System::Object^ sender, System::EventArgs^ e) {
  385. zapis(0);
  386. }
  387. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  388. zapis(1);
  389. }
  390. private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
  391. zapis(2);
  392. }
  393. private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
  394. zapis(3);
  395. }
  396. private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
  397. zapis(4);
  398. }
  399. private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
  400. zapis(5);
  401. }
  402. private: System::Void buttonClear_Click(System::Object^ sender, System::EventArgs^ e) {
  403. // Очистка полей ввода, вывода, счётчика введённых цифр
  404. tb6->Text = "0";
  405. tb10->Text = "0";
  406. n = 0;
  407. }
  408. private: System::Void buttonDot_Click(System::Object^ sender, System::EventArgs^ e) {
  409. // Нажатие на кнопку разделителя
  410. if (tb6->Text->Contains(".") == 0) // Проверка на наличие разделителя
  411. {
  412. if (tb6->Text == "0" || tb6->Text == "-0") n++; // если в целой части 0 или -0, считаем 0 как цифру.
  413. tb6->Text = tb6->Text + "."; // Дописываем разделитель справа
  414. }
  415. }
  416. private: System::Void buttonZnak_Click(System::Object^ sender, System::EventArgs^ e) {
  417. // Нажатие на кнопку "+/-"
  418. if (tb6->Text->Contains("-") == 0) tb6->Text = "-" + tb6->Text; // Если минуса не было, дописываем слева
  419. else
  420. {
  421. tb6->Text = tb6->Text->Replace("-", ""); // если минус был - меняем на пустоту (удаляем минус).
  422. }
  423. }
  424. private: System::Void buttonBackSpace_Click(System::Object^ sender, System::EventArgs^ e) {
  425. // Нажатие на кнопку BackSpace (Удаление последнего символа)
  426. bool dot = tb6->Text->Contains("."); // Проверка на разделитель
  427. if (n == 1 && dot == 0) // 1 цифра и разделителя нет
  428. {
  429. if (tb6->Text->Contains("-") == 1)
  430. {
  431. tb6->Text = "-" + "0";
  432. n--;
  433. }
  434. else
  435. {
  436. n--;
  437. tb6->Text = "0";
  438. }
  439. }
  440. if (n == 1 && dot == 1) // 1 цифра и есть разделитель
  441. {
  442. tb6->Text = tb6->Text->Remove(tb6->Text->Length - 1, 1);
  443. }
  444. if (n > 1) // цифр больше чем 1
  445. {
  446. tb6->Text = tb6->Text->Remove(tb6->Text->Length - 1, 1);
  447. if (dot == tb6->Text->Contains(".")) n--;
  448. }
  449. if (n == 11) tb10->Text = vivod; // Возвращение ответа в поле вывода, если там было сообщение о переполнении
  450. }
  451. private: System::Void buttonRavno_Click(System::Object^ sender, System::EventArgs^ e) {
  452. // кнопка "="
  453. bool minus = tb6->Text->Contains("-");
  454. if (tb6->Text->Contains(".") == 0)
  455. {
  456. if (minus == 0) tb10->Text = cel(tb6->Text->Replace("-", ""));
  457. else
  458. {
  459. tb10->Text = "-" + cel(tb6->Text->Replace("-", ""));
  460. }
  461. }
  462. else
  463. {
  464. _int64 celoe = _int64(Convert::ToDouble(tb6->Text));
  465. String^ a = tb6->Text; // новая строка с элементами текстбокса
  466. long long position = 0; // переменная для определения позиции разделителя
  467. long long size = tb6->Text->Length; // Количество символов в строке
  468. for (long long i = 0; i < size; i++) // цикл подсчёта позиции разделителя
  469. {
  470. if (a[i] == '.')
  471. {
  472. position = i;
  473. break;
  474. }
  475. }
  476. a = tb6->Text->Remove(0, position); // Удаление целой части при наличии остатка
  477. if (minus == 0)
  478. {
  479. tb10->Text = cel(Convert::ToString(celoe));
  480. long long y = tb10->Text->Length;
  481. y++;
  482. if (a != ".") tb10->Text += ost(a, y)->Remove(0, 1); // Проверка на наличие символов в дробной части.
  483. }
  484. else
  485. {
  486. tb10->Text = "-" + cel(Convert::ToString(celoe)->Replace("-", ""));
  487. long long y = tb10->Text->Length;
  488. if (a != ".") tb10->Text += ost(a, y)->Remove(0, 1);
  489. }
  490. }
  491. if (tb6->Text == "0") tb10->Text = "0";
  492. if (tb6->Text == "-0") tb10->Text = "-0";
  493. 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";
  494.  
  495. vivod = tb10->Text;
  496. }
  497. private: System::Void helpToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  498. // Нажатие на "Help"
  499. MyForm1^ newForm = gcnew MyForm1; // создание формы справки
  500. newForm->ShowDialog(); // инициализация формы справки
  501. }
  502. };
  503. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement