Advertisement
dequone

kvadrat

Feb 25th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.23 KB | None | 0 0
  1. #pragma once
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "stdafx.h"
  5. double kvad_ok( double a,double b,double c);
  6. double x(double *x1, double *x2, double a, double b,double c);
  7. double a,b,c,x1,x2;
  8.  
  9. namespace kvadrat {
  10.  
  11.     using namespace System;
  12.     using namespace System::ComponentModel;
  13.     using namespace System::Collections;
  14.     using namespace System::Windows::Forms;
  15.     using namespace System::Data;
  16.     using namespace System::Drawing;
  17.  
  18.     /// <summary>
  19.     /// Summary for Form1
  20.     /// </summary>
  21.     public ref class Form1 : public System::Windows::Forms::Form
  22.     {
  23.     public:
  24.         Form1(void)
  25.         {
  26.             InitializeComponent();
  27.             //
  28.             //TODO: Add the constructor code here
  29.             //
  30.         }
  31.  
  32.     protected:
  33.         /// <summary>
  34.         /// Clean up any resources being used.
  35.         /// </summary>
  36.         ~Form1()
  37.         {
  38.             if (components)
  39.             {
  40.                 delete components;
  41.             }
  42.         }
  43.     private: System::Windows::Forms::Label^  lbl_a;
  44.     protected:
  45.     private: System::Windows::Forms::Label^  lbl_b;
  46.     private: System::Windows::Forms::Label^  lbl_c;
  47.     private: System::Windows::Forms::Label^  lbl_res;
  48.     private: System::Windows::Forms::TextBox^  edt_a;
  49.     private: System::Windows::Forms::TextBox^  edt_b;
  50.     private: System::Windows::Forms::TextBox^  edt_c;
  51.     private: System::Windows::Forms::Button^  btn_res;
  52.     private: System::Windows::Forms::Button^  btn_exit;
  53.  
  54.     private:
  55.         /// <summary>
  56.         /// Required designer variable.
  57.         /// </summary>
  58.         System::ComponentModel::Container ^components;
  59.  
  60. #pragma region Windows Form Designer generated code
  61.         /// <summary>
  62.         /// Required method for Designer support - do not modify
  63.         /// the contents of this method with the code editor.
  64.         /// </summary>
  65.         void InitializeComponent(void)
  66.         {
  67.             this->lbl_a = (gcnew System::Windows::Forms::Label());
  68.             this->lbl_b = (gcnew System::Windows::Forms::Label());
  69.             this->lbl_c = (gcnew System::Windows::Forms::Label());
  70.             this->lbl_res = (gcnew System::Windows::Forms::Label());
  71.             this->edt_a = (gcnew System::Windows::Forms::TextBox());
  72.             this->edt_b = (gcnew System::Windows::Forms::TextBox());
  73.             this->edt_c = (gcnew System::Windows::Forms::TextBox());
  74.             this->btn_res = (gcnew System::Windows::Forms::Button());
  75.             this->btn_exit = (gcnew System::Windows::Forms::Button());
  76.             this->SuspendLayout();
  77.             //
  78.             // lbl_a
  79.             //
  80.             this->lbl_a->AutoSize = true;
  81.             this->lbl_a->Location = System::Drawing::Point(16, 33);
  82.             this->lbl_a->Name = L"lbl_a";
  83.             this->lbl_a->Size = System::Drawing::Size(13, 13);
  84.             this->lbl_a->TabIndex = 0;
  85.             this->lbl_a->Text = L"a";
  86.             //
  87.             // lbl_b
  88.             //
  89.             this->lbl_b->AutoSize = true;
  90.             this->lbl_b->Location = System::Drawing::Point(16, 73);
  91.             this->lbl_b->Name = L"lbl_b";
  92.             this->lbl_b->Size = System::Drawing::Size(13, 13);
  93.             this->lbl_b->TabIndex = 1;
  94.             this->lbl_b->Text = L"b";
  95.             //
  96.             // lbl_c
  97.             //
  98.             this->lbl_c->AutoSize = true;
  99.             this->lbl_c->Location = System::Drawing::Point(16, 114);
  100.             this->lbl_c->Name = L"lbl_c";
  101.             this->lbl_c->Size = System::Drawing::Size(13, 13);
  102.             this->lbl_c->TabIndex = 2;
  103.             this->lbl_c->Text = L"c";
  104.             //
  105.             // lbl_res
  106.             //
  107.             this->lbl_res->AutoSize = true;
  108.             this->lbl_res->Location = System::Drawing::Point(16, 174);
  109.             this->lbl_res->Name = L"lbl_res";
  110.             this->lbl_res->Size = System::Drawing::Size(59, 13);
  111.             this->lbl_res->TabIndex = 3;
  112.             this->lbl_res->Text = L"Результат";
  113.             //
  114.             // edt_a
  115.             //
  116.             this->edt_a->Location = System::Drawing::Point(180, 33);
  117.             this->edt_a->Name = L"edt_a";
  118.             this->edt_a->Size = System::Drawing::Size(100, 20);
  119.             this->edt_a->TabIndex = 4;
  120.             //
  121.             // edt_b
  122.             //
  123.             this->edt_b->Location = System::Drawing::Point(180, 73);
  124.             this->edt_b->Name = L"edt_b";
  125.             this->edt_b->Size = System::Drawing::Size(100, 20);
  126.             this->edt_b->TabIndex = 5;
  127.             //
  128.             // edt_c
  129.             //
  130.             this->edt_c->Location = System::Drawing::Point(180, 114);
  131.             this->edt_c->Name = L"edt_c";
  132.             this->edt_c->Size = System::Drawing::Size(100, 20);
  133.             this->edt_c->TabIndex = 6;
  134.             //
  135.             // btn_res
  136.             //
  137.             this->btn_res->Location = System::Drawing::Point(180, 174);
  138.             this->btn_res->Name = L"btn_res";
  139.             this->btn_res->Size = System::Drawing::Size(75, 23);
  140.             this->btn_res->TabIndex = 7;
  141.             this->btn_res->Text = L"Решить";
  142.             this->btn_res->UseVisualStyleBackColor = true;
  143.             this->btn_res->Click += gcnew System::EventHandler(this, &Form1::btn_res_Click);
  144.             //
  145.             // btn_exit
  146.             //
  147.             this->btn_exit->Location = System::Drawing::Point(98, 221);
  148.             this->btn_exit->Name = L"btn_exit";
  149.             this->btn_exit->Size = System::Drawing::Size(75, 23);
  150.             this->btn_exit->TabIndex = 8;
  151.             this->btn_exit->Text = L"Выход";
  152.             this->btn_exit->UseVisualStyleBackColor = true;
  153.             this->btn_exit->Click += gcnew System::EventHandler(this, &Form1::btn_exit_Click);
  154.             //
  155.             // Form1
  156.             //
  157.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  158.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  159.             this->ClientSize = System::Drawing::Size(292, 271);
  160.             this->Controls->Add(this->btn_exit);
  161.             this->Controls->Add(this->btn_res);
  162.             this->Controls->Add(this->edt_c);
  163.             this->Controls->Add(this->edt_b);
  164.             this->Controls->Add(this->edt_a);
  165.             this->Controls->Add(this->lbl_res);
  166.             this->Controls->Add(this->lbl_c);
  167.             this->Controls->Add(this->lbl_b);
  168.             this->Controls->Add(this->lbl_a);
  169.             this->Name = L"Form1";
  170.             this->Text = L"Form1";
  171.             this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
  172.             this->ResumeLayout(false);
  173.             this->PerformLayout();
  174.  
  175.         }
  176. #pragma endregion
  177.     private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
  178.              }
  179.  
  180. private: System::Void btn_res_Click(System::Object^  sender, System::EventArgs^  e)
  181.          {
  182.              
  183.              //double a,b,c;
  184.              a = Convert::ToDouble(edt_a->Text);
  185.              if (a<0) lbl_res->Text = "Квадратного уравнения не существует" ;
  186.              else
  187.              {
  188.                  b = Convert::ToDouble(edt_b->Text);
  189.                  c = Convert::ToDouble(edt_c->Text);
  190.                  double D = kvad_ok(a, b, c);
  191.  
  192.                  if (D == -1.0) lbl_res->Text = "Корней нет";
  193.                  else if (D == 0.0)
  194.                  {
  195.                      lbl_res->Text = "x = " + x1;
  196.                  }
  197.                  else if (D > 0)
  198.                      lbl_res->Text = "x1 = " + x1 + ", x2 = " + x2;
  199.              }
  200.        
  201.              /*  b = Convert::ToDouble(edt_b->Text);
  202.               c = Convert::ToDouble(edt_c->Text);
  203.              lbl_res->Text = "x1=  " + Convert::ToString(kvad_ok(a, b, c)) + Convert::ToString(x(a, b, c,x1,x2,d))
  204.                */
  205.  
  206.            
  207.             /*::System::Windows::Forms::DialogResult rc =MessageBox::Show("Нажмите на кнопку Да или нет.", "Да/Нет", MessageBoxButtons::YesNo, MessageBoxIcon::Question);
  208.             if (rc== ::System::Windows::Forms:: DialogResult:: No)
  209.                 MessageBox::Show("Нажали Нет");
  210.             else
  211.                 MessageBox::Show("Нажали Да");*/
  212.          
  213.          }
  214.  
  215. private: System::Void btn_exit_Click(System::Object^  sender, System::EventArgs^  e)
  216.          {
  217.          Close();
  218.          }
  219. };
  220. }
  221.  
  222.     double kvad_ok(double a, double b, double c)
  223.         {                      
  224.             double d = 0.0;
  225.             d = b*b -4*a*c;
  226.                 if(d<0)
  227.                     return -1.0;
  228.                 else if(d==0)
  229.                 {
  230.                     x1 = -b/2*a;
  231.                     x2 = 0.0;
  232.                     return 0.0;
  233.                 }
  234.                 else if(d>0)
  235.                 {
  236.                     x1=( -b - sqrt(d)/2*a);
  237.                     x2=( -b+ sqrt(d)/2*a);
  238.                     return d;  
  239.                 }
  240.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement