Advertisement
xxxdanilion

Untitled

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