Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.48 KB | None | 0 0
  1. #pragma once
  2.  
  3. namespace Informatika2ND {
  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.     /// <summary>
  13.     /// Summary for MyForm
  14.     /// </summary>
  15.     public ref class MyForm : public System::Windows::Forms::Form
  16.     {
  17.     public:
  18.         MyForm(void)
  19.         {
  20.             InitializeComponent();
  21.             //
  22.             //TODO: Add the constructor code here
  23.             //
  24.         }
  25.  
  26.     protected:
  27.         /// <summary>
  28.         /// Clean up any resources being used.
  29.         /// </summary>
  30.         ~MyForm()
  31.         {
  32.             if (components)
  33.             {
  34.                 delete components;
  35.             }
  36.         }
  37.     private: System::Windows::Forms::TextBox^  textBox1;
  38.     protected:
  39.     private: System::Windows::Forms::Label^  label1;
  40.  
  41.  
  42.  
  43.     private: System::Windows::Forms::Label^  label2;
  44.     private: System::Windows::Forms::Label^  label3;
  45.     private: System::Windows::Forms::Label^  label4;
  46.     private: System::Windows::Forms::Label^  label5;
  47.     private: System::Windows::Forms::Button^  button1;
  48.  
  49.     private:
  50.         /// <summary>
  51.         /// Required designer variable.
  52.         /// </summary>
  53.         System::ComponentModel::Container ^components;
  54.  
  55.  
  56. #pragma region Windows Form Designer generated code
  57.         /// <summary>
  58.         /// Required method for Designer support - do not modify
  59.         /// the contents of this method with the code editor.
  60.         /// </summary>
  61.         void InitializeComponent(void)
  62.         {
  63.             this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  64.             this->label1 = (gcnew System::Windows::Forms::Label());
  65.             this->label2 = (gcnew System::Windows::Forms::Label());
  66.             this->label3 = (gcnew System::Windows::Forms::Label());
  67.             this->label4 = (gcnew System::Windows::Forms::Label());
  68.             this->label5 = (gcnew System::Windows::Forms::Label());
  69.             this->button1 = (gcnew System::Windows::Forms::Button());
  70.             this->SuspendLayout();
  71.             //
  72.             // textBox1
  73.             //
  74.             this->textBox1->Location = System::Drawing::Point(206, 28);
  75.             this->textBox1->Name = L"textBox1";
  76.             this->textBox1->Size = System::Drawing::Size(100, 20);
  77.             this->textBox1->TabIndex = 0;
  78.             //
  79.             // label1
  80.             //
  81.             this->label1->AutoSize = true;
  82.             this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  83.                 static_cast<System::Byte>(0)));
  84.             this->label1->Location = System::Drawing::Point(12, 23);
  85.             this->label1->Name = L"label1";
  86.             this->label1->Size = System::Drawing::Size(188, 25);
  87.             this->label1->TabIndex = 1;
  88.             this->label1->Text = L"Sveikasis skaicius";
  89.             //
  90.             // label2
  91.             //
  92.             this->label2->AutoSize = true;
  93.             this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  94.                 static_cast<System::Byte>(0)));
  95.             this->label2->Location = System::Drawing::Point(131, 84);
  96.             this->label2->Name = L"label2";
  97.             this->label2->Size = System::Drawing::Size(175, 25);
  98.             this->label2->TabIndex = 5;
  99.             this->label2->Text = L"Skaicius turi tiek:";
  100.             //
  101.             // label3
  102.             //
  103.             this->label3->AutoSize = true;
  104.             this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  105.                 static_cast<System::Byte>(0)));
  106.             this->label3->Location = System::Drawing::Point(2, 155);
  107.             this->label3->Name = L"label3";
  108.             this->label3->Size = System::Drawing::Size(76, 18);
  109.             this->label3->TabIndex = 6;
  110.             this->label3->Text = L"Vienetuku:";
  111.             //
  112.             // label4
  113.             //
  114.             this->label4->AutoSize = true;
  115.             this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  116.                 static_cast<System::Byte>(0)));
  117.             this->label4->Location = System::Drawing::Point(233, 155);
  118.             this->label4->Name = L"label4";
  119.             this->label4->Size = System::Drawing::Size(73, 18);
  120.             this->label4->TabIndex = 7;
  121.             this->label4->Text = L"Trejetuku:";
  122.             //
  123.             // label5
  124.             //
  125.             this->label5->AutoSize = true;
  126.             this->label5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  127.                 static_cast<System::Byte>(0)));
  128.             this->label5->Location = System::Drawing::Point(100, 212);
  129.             this->label5->Name = L"label5";
  130.             this->label5->Size = System::Drawing::Size(82, 18);
  131.             this->label5->TabIndex = 8;
  132.             this->label5->Text = L"Penketuku:";
  133.             //
  134.             // button1
  135.             //
  136.             this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  137.                 static_cast<System::Byte>(0)));
  138.             this->button1->Location = System::Drawing::Point(136, 58);
  139.             this->button1->Name = L"button1";
  140.             this->button1->Size = System::Drawing::Size(145, 23);
  141.             this->button1->TabIndex = 9;
  142.             this->button1->Text = L"Apskaiciuoti";
  143.             this->button1->UseVisualStyleBackColor = true;
  144.             this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  145.             //
  146.             // MyForm
  147.             //
  148.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  149.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  150.             this->ClientSize = System::Drawing::Size(435, 257);
  151.             this->Controls->Add(this->button1);
  152.             this->Controls->Add(this->label5);
  153.             this->Controls->Add(this->label4);
  154.             this->Controls->Add(this->label3);
  155.             this->Controls->Add(this->label2);
  156.             this->Controls->Add(this->label1);
  157.             this->Controls->Add(this->textBox1);
  158.             this->Name = L"MyForm";
  159.             this->Text = L"Namu darbas 2";
  160.             this->ResumeLayout(false);
  161.             this->PerformLayout();
  162.  
  163.         }
  164. #pragma endregion
  165.     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) // Kai paspaudi mygtuka atlieka visus skaiciavimus
  166.     {
  167.         int skaicius;
  168.         skaicius = int::Parse(textBox1->Text); //Paema ka is textboxo skaiciu ir pakeicia int skaicius reiksme i ta.
  169.         // iskvieciu is funkcijos skaicius 1, 3, 5.
  170.         label3->Text = "Vienetukai: " + sprendimas(skaicius, 1).ToString();
  171.         label4->Text = "Trejetukai: " + sprendimas(skaicius, 3).ToString();
  172.         label5->Text = "Penketukai: " + sprendimas(skaicius, 5).ToString();
  173.  
  174.     }
  175.  
  176.     int sprendimas(int skaicius, int ieskotiSkc)
  177.     {
  178.         int kiekis = 0;
  179.         while (skaicius != 0)
  180.         {
  181.             // pasiema paskutini skc.
  182.             skaicius %= 10;
  183.             if (skaicius == ieskotiSkc)
  184.                 kiekis++;
  185.            
  186.             skaicius /= 10;
  187.         }
  188.         return kiekis;
  189.     }
  190.     };
  191. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement