Sharof rashidov nomidagi samarqand davlat universiteti intelektual tizimlar va innvation tizimlar fakulteti dasturiy injinirngi yo
Download 80.4 Kb.
|
Javohir Achilov Labaratoriya
2-Topshiriq.
Masala sharti: (3) [2; n] intervalda bo’luvchilar yig’indisi eng katta bo’lgan natural sonni toping. (Natija Labelga chop etilsin) Dasturning visual ko’rinishi. Dastur kodi: #pragma once namespace CppWinForm1 { using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// /// Summary for MyForm /// public ref class MyForm : public System::Windows::Forms::Form { public: MyForm(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// /// Clean up any resources being used. /// ~MyForm() { if (components) { delete components; } } private: System::Windows::Forms::Button^ button1; protected: private: System::Windows::Forms::Label^ S; private: System::Windows::Forms::TextBox^ textBox1; private: /// /// Required designer variable. /// System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// void InitializeComponent(void) { this->button1 = (gcnew System::Windows::Forms::Button()); this->S = (gcnew System::Windows::Forms::Label()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->SuspendLayout(); // // button1 // this->button1->BackColor = System::Drawing::Color::Cyan; this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, static_cast this->button1->Location = System::Drawing::Point(58, 95); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(114, 35); this->button1->TabIndex = 1; this->button1->Text = L"Hisoblash"; this->button1->UseVisualStyleBackColor = false; this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); // // S // this->S->AutoSize = true; this->S->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast this->S->Location = System::Drawing::Point(80, 170); this->S->Name = L"S"; this->S->Size = System::Drawing::Size(61, 24); this->S->TabIndex = 4; this->S->Text = L"Natija:"; // // textBox1 // this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast this->textBox1->Location = System::Drawing::Point(44, 25); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(148, 31); this->textBox1->TabIndex = 5; this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox1_KeyPress); // // MyForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->BackColor = System::Drawing::SystemColors::AppWorkspace; this->ClientSize = System::Drawing::Size(235, 216); this->Controls->Add(this->textBox1); this->Controls->Add(this->S); this->Controls->Add(this->button1); this->Name = L"MyForm"; this->Text = L"MyForm"; this->ResumeLayout(false); this->PerformLayout(); }
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { int n; n = Convert::ToInt16(textBox1->Text); int s = 0, k = 0, max=0; MessageBox::Show("Qiymat noto'g'ri kiritildi!", "Xatolik", MessageBoxButtons::OK, MessageBoxIcon::Error); for (size_t i = n; i >= 2; i--) {
for (size_t j=n; j > 0; j--) { if (i%j == 0) { s++; } } if (max < s) { max = s; k = i; } } S->Text = "Natija:" + Convert::ToString(k); } private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { if (e->KeyChar == '.') { if (this->textBox1->Text->Contains(".") && !this->textBox1->SelectedText->Contains(".")) e->Handled = true; } // Allow negative numbers else if (e->KeyChar == '-' && !(this->textBox1->Text->Contains("-"))) { e->Handled = true; textBox1->Text = "-" + textBox1->Text; } // Accept only digits ".", "-" and the Backspace character else if (!Char::IsDigit(e->KeyChar) && e->KeyChar != 0x08) { e->Handled = true; } } }; }
Download 80.4 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling