Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.33 KB | None | 0 0
  1. #pragma once
  2.  
  3. namespace Cw2 {
  4.  
  5. using namespace System;
  6. using namespace System::ComponentModel;
  7. using namespace System::Collections;
  8. using namespace System::Windows::Forms;
  9. using namespace System::Data;
  10. using namespace System::Drawing;
  11.  
  12. const int RS=10; //rozmiar stosu
  13. int stos[RS]; // lub wchar_t stos[RS]; // stos
  14. int js=0; //lub int js=-1; // indeks stosu
  15.  
  16. /// <summary>
  17. /// Summary for MyForm
  18. /// </summary>
  19. public ref class MyForm : public System::Windows::Forms::Form
  20. {
  21. public:
  22. MyForm(void)
  23. {
  24. InitializeComponent();
  25. //
  26. //TODO: Add the constructor code here
  27. //
  28. }
  29.  
  30. protected:
  31. /// <summary>
  32. /// Clean up any resources being used.
  33. /// </summary>
  34. ~MyForm()
  35. {
  36. if (components)
  37. {
  38. delete components;
  39. }
  40. }
  41. private: System::Windows::Forms::ListBox^ listBox1;
  42. protected:
  43. private: System::Windows::Forms::NumericUpDown^ numericUpDown1;
  44. private: System::Windows::Forms::StatusBar^ statusBar1;
  45. private: System::Windows::Forms::Button^ buttonZdejmij;
  46.  
  47. private: System::Windows::Forms::Button^ buttonDodaj;
  48.  
  49. private: System::Windows::Forms::NumericUpDown^ numericUpDown2;
  50.  
  51. private:
  52. /// <summary>
  53. /// Required designer variable.
  54. /// </summary>
  55. System::ComponentModel::Container ^components;
  56.  
  57. #pragma region Windows Form Designer generated code
  58. /// <summary>
  59. /// Required method for Designer support - do not modify
  60. /// the contents of this method with the code editor.
  61. /// </summary>
  62. void InitializeComponent(void)
  63. {
  64. this->listBox1 = (gcnew System::Windows::Forms::ListBox());
  65. this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
  66. this->statusBar1 = (gcnew System::Windows::Forms::StatusBar());
  67. this->buttonZdejmij = (gcnew System::Windows::Forms::Button());
  68. this->buttonDodaj = (gcnew System::Windows::Forms::Button());
  69. this->numericUpDown2 = (gcnew System::Windows::Forms::NumericUpDown());
  70. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown1))->BeginInit();
  71. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown2))->BeginInit();
  72. this->SuspendLayout();
  73. //
  74. // listBox1
  75. //
  76. this->listBox1->FormattingEnabled = true;
  77. this->listBox1->Location = System::Drawing::Point(12, 15);
  78. this->listBox1->Name = L"listBox1";
  79. this->listBox1->Size = System::Drawing::Size(279, 95);
  80. this->listBox1->TabIndex = 0;
  81. //
  82. // numericUpDown1
  83. //
  84. this->numericUpDown1->Location = System::Drawing::Point(12, 126);
  85. this->numericUpDown1->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {100, 0, 0, System::Int32::MinValue});
  86. this->numericUpDown1->Name = L"numericUpDown1";
  87. this->numericUpDown1->Size = System::Drawing::Size(120, 20);
  88. this->numericUpDown1->TabIndex = 1;
  89. this->numericUpDown1->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
  90. //
  91. // statusBar1
  92. //
  93. this->statusBar1->Location = System::Drawing::Point(0, 239);
  94. this->statusBar1->Name = L"statusBar1";
  95. this->statusBar1->Size = System::Drawing::Size(313, 22);
  96. this->statusBar1->TabIndex = 2;
  97. this->statusBar1->Text = L"statusBar1";
  98. //
  99. // buttonZdejmij
  100. //
  101. this->buttonZdejmij->Location = System::Drawing::Point(171, 152);
  102. this->buttonZdejmij->Name = L"buttonZdejmij";
  103. this->buttonZdejmij->Size = System::Drawing::Size(75, 23);
  104. this->buttonZdejmij->TabIndex = 3;
  105. this->buttonZdejmij->Text = L"Zdejmij";
  106. this->buttonZdejmij->UseVisualStyleBackColor = true;
  107. this->buttonZdejmij->Click += gcnew System::EventHandler(this, &MyForm::buttonZdejmij_Click);
  108. //
  109. // buttonDodaj
  110. //
  111. this->buttonDodaj->Location = System::Drawing::Point(12, 152);
  112. this->buttonDodaj->Name = L"buttonDodaj";
  113. this->buttonDodaj->Size = System::Drawing::Size(75, 23);
  114. this->buttonDodaj->TabIndex = 4;
  115. this->buttonDodaj->Text = L"Dodaj";
  116. this->buttonDodaj->UseVisualStyleBackColor = true;
  117. this->buttonDodaj->Click += gcnew System::EventHandler(this, &MyForm::buttonDodaj_Click);
  118. //
  119. // numericUpDown2
  120. //
  121. this->numericUpDown2->Location = System::Drawing::Point(171, 126);
  122. this->numericUpDown2->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {100, 0, 0, System::Int32::MinValue});
  123. this->numericUpDown2->Name = L"numericUpDown2";
  124. this->numericUpDown2->Size = System::Drawing::Size(120, 20);
  125. this->numericUpDown2->TabIndex = 5;
  126. //
  127. // MyForm
  128. //
  129. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  130. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  131. this->ClientSize = System::Drawing::Size(313, 261);
  132. this->Controls->Add(this->numericUpDown2);
  133. this->Controls->Add(this->buttonDodaj);
  134. this->Controls->Add(this->buttonZdejmij);
  135. this->Controls->Add(this->statusBar1);
  136. this->Controls->Add(this->numericUpDown1);
  137. this->Controls->Add(this->listBox1);
  138. this->Name = L"MyForm";
  139. this->Text = L"MyForm";
  140. this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
  141. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown1))->EndInit();
  142. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown2))->EndInit();
  143. this->ResumeLayout(false);
  144.  
  145. }
  146. #pragma endregion
  147. private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e)
  148. {
  149.  
  150. }
  151. private: System::Void buttonDodaj_Click(System::Object^ sender, System::EventArgs^ e)
  152. {
  153. if (js>=RS) //lub if (js>=RS-1)
  154. {
  155. statusBar1->Text = "Stos jest zapełniony";
  156. }
  157. else
  158. {
  159. // instrukcje odkładania elementu na stos
  160. stos[js++]=System::Decimal::ToInt32(numericUpDown1->Value);
  161. listBox1->Items->Clear();
  162. for (int i=0;i<=js;i++) listBox1->Items->Add(stos[i]);
  163. listBox1->SelectedIndex = js;
  164. }
  165.  
  166. }
  167. private: System::Void buttonZdejmij_Click(System::Object^ sender, System::EventArgs^ e)
  168. {
  169. if (js==0) // lub if (js<0)
  170. {
  171. statusBar1->Text = "Stos jest pusty";
  172. }
  173. else
  174. {
  175. // instrukcje zdejmowania elementu ze stosu
  176. numericUpDown2->Value=stos[--js];
  177. listBox1->Items->Clear();
  178. for (int i=0;i<=js;i++) listBox1->Items->Add(stos[i]);
  179. listBox1->SelectedIndex = js;
  180. }
  181. }
  182. };
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement