Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <stdlib.h>
- #include <math.h>
- #include "stdafx.h"
- double kvad_ok( double a,double b,double c);
- double x(double *x1, double *x2, double a, double b,double c);
- double a,b,c,x1,x2;
- namespace kvadrat {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- /// <summary>
- /// Summary for Form1
- /// </summary>
- public ref class Form1 : public System::Windows::Forms::Form
- {
- public:
- Form1(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~Form1()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Label^ lbl_a;
- protected:
- private: System::Windows::Forms::Label^ lbl_b;
- private: System::Windows::Forms::Label^ lbl_c;
- private: System::Windows::Forms::Label^ lbl_res;
- private: System::Windows::Forms::TextBox^ edt_a;
- private: System::Windows::Forms::TextBox^ edt_b;
- private: System::Windows::Forms::TextBox^ edt_c;
- private: System::Windows::Forms::Button^ btn_res;
- private: System::Windows::Forms::Button^ btn_exit;
- private:
- /// <summary>
- /// Required designer variable.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- this->lbl_a = (gcnew System::Windows::Forms::Label());
- this->lbl_b = (gcnew System::Windows::Forms::Label());
- this->lbl_c = (gcnew System::Windows::Forms::Label());
- this->lbl_res = (gcnew System::Windows::Forms::Label());
- this->edt_a = (gcnew System::Windows::Forms::TextBox());
- this->edt_b = (gcnew System::Windows::Forms::TextBox());
- this->edt_c = (gcnew System::Windows::Forms::TextBox());
- this->btn_res = (gcnew System::Windows::Forms::Button());
- this->btn_exit = (gcnew System::Windows::Forms::Button());
- this->SuspendLayout();
- //
- // lbl_a
- //
- this->lbl_a->AutoSize = true;
- this->lbl_a->Location = System::Drawing::Point(16, 33);
- this->lbl_a->Name = L"lbl_a";
- this->lbl_a->Size = System::Drawing::Size(13, 13);
- this->lbl_a->TabIndex = 0;
- this->lbl_a->Text = L"a";
- //
- // lbl_b
- //
- this->lbl_b->AutoSize = true;
- this->lbl_b->Location = System::Drawing::Point(16, 73);
- this->lbl_b->Name = L"lbl_b";
- this->lbl_b->Size = System::Drawing::Size(13, 13);
- this->lbl_b->TabIndex = 1;
- this->lbl_b->Text = L"b";
- //
- // lbl_c
- //
- this->lbl_c->AutoSize = true;
- this->lbl_c->Location = System::Drawing::Point(16, 114);
- this->lbl_c->Name = L"lbl_c";
- this->lbl_c->Size = System::Drawing::Size(13, 13);
- this->lbl_c->TabIndex = 2;
- this->lbl_c->Text = L"c";
- //
- // lbl_res
- //
- this->lbl_res->AutoSize = true;
- this->lbl_res->Location = System::Drawing::Point(16, 174);
- this->lbl_res->Name = L"lbl_res";
- this->lbl_res->Size = System::Drawing::Size(59, 13);
- this->lbl_res->TabIndex = 3;
- this->lbl_res->Text = L"Результат";
- //
- // edt_a
- //
- this->edt_a->Location = System::Drawing::Point(180, 33);
- this->edt_a->Name = L"edt_a";
- this->edt_a->Size = System::Drawing::Size(100, 20);
- this->edt_a->TabIndex = 4;
- //
- // edt_b
- //
- this->edt_b->Location = System::Drawing::Point(180, 73);
- this->edt_b->Name = L"edt_b";
- this->edt_b->Size = System::Drawing::Size(100, 20);
- this->edt_b->TabIndex = 5;
- //
- // edt_c
- //
- this->edt_c->Location = System::Drawing::Point(180, 114);
- this->edt_c->Name = L"edt_c";
- this->edt_c->Size = System::Drawing::Size(100, 20);
- this->edt_c->TabIndex = 6;
- //
- // btn_res
- //
- this->btn_res->Location = System::Drawing::Point(180, 174);
- this->btn_res->Name = L"btn_res";
- this->btn_res->Size = System::Drawing::Size(75, 23);
- this->btn_res->TabIndex = 7;
- this->btn_res->Text = L"Решить";
- this->btn_res->UseVisualStyleBackColor = true;
- this->btn_res->Click += gcnew System::EventHandler(this, &Form1::btn_res_Click);
- //
- // btn_exit
- //
- this->btn_exit->Location = System::Drawing::Point(98, 221);
- this->btn_exit->Name = L"btn_exit";
- this->btn_exit->Size = System::Drawing::Size(75, 23);
- this->btn_exit->TabIndex = 8;
- this->btn_exit->Text = L"Выход";
- this->btn_exit->UseVisualStyleBackColor = true;
- this->btn_exit->Click += gcnew System::EventHandler(this, &Form1::btn_exit_Click);
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(292, 271);
- this->Controls->Add(this->btn_exit);
- this->Controls->Add(this->btn_res);
- this->Controls->Add(this->edt_c);
- this->Controls->Add(this->edt_b);
- this->Controls->Add(this->edt_a);
- this->Controls->Add(this->lbl_res);
- this->Controls->Add(this->lbl_c);
- this->Controls->Add(this->lbl_b);
- this->Controls->Add(this->lbl_a);
- this->Name = L"Form1";
- this->Text = L"Form1";
- this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void btn_res_Click(System::Object^ sender, System::EventArgs^ e)
- {
- //double a,b,c;
- a = Convert::ToDouble(edt_a->Text);
- if (a<0) lbl_res->Text = "Квадратного уравнения не существует" ;
- else
- {
- b = Convert::ToDouble(edt_b->Text);
- c = Convert::ToDouble(edt_c->Text);
- double D = kvad_ok(a, b, c);
- if (D == -1.0) lbl_res->Text = "Корней нет";
- else if (D == 0.0)
- {
- lbl_res->Text = "x = " + x1;
- }
- else if (D > 0)
- lbl_res->Text = "x1 = " + x1 + ", x2 = " + x2;
- }
- /* b = Convert::ToDouble(edt_b->Text);
- c = Convert::ToDouble(edt_c->Text);
- lbl_res->Text = "x1= " + Convert::ToString(kvad_ok(a, b, c)) + Convert::ToString(x(a, b, c,x1,x2,d))
- */
- /*::System::Windows::Forms::DialogResult rc =MessageBox::Show("Нажмите на кнопку Да или нет.", "Да/Нет", MessageBoxButtons::YesNo, MessageBoxIcon::Question);
- if (rc== ::System::Windows::Forms:: DialogResult:: No)
- MessageBox::Show("Нажали Нет");
- else
- MessageBox::Show("Нажали Да");*/
- }
- private: System::Void btn_exit_Click(System::Object^ sender, System::EventArgs^ e)
- {
- Close();
- }
- };
- }
- double kvad_ok(double a, double b, double c)
- {
- double d = 0.0;
- d = b*b -4*a*c;
- if(d<0)
- return -1.0;
- else if(d==0)
- {
- x1 = -b/2*a;
- x2 = 0.0;
- return 0.0;
- }
- else if(d>0)
- {
- x1=( -b - sqrt(d)/2*a);
- x2=( -b+ sqrt(d)/2*a);
- return d;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement