aes110

Mishvaha Ribuit Solver *Ron Serruya*

May 15th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Misvaha_Ribuit_Slover
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();            
  17.         }
  18.         decimal a, b, c, Delta, X1, X2, Delta_Sqrt1, X_kodkod, Y_kodkod;
  19.         double Delta_Sqrt;
  20.         private void Num_A_ValueChanged(object sender, EventArgs e)
  21.         {
  22.             if (Num_A.Value == 0)
  23.                 Num_A.ForeColor = System.Drawing.Color.Red;
  24.             else
  25.                 Num_A.ForeColor = System.Drawing.SystemColors.WindowText;
  26.         }
  27.  
  28.         private void button1_Click(object sender, EventArgs e)
  29.         {
  30.             try
  31.             {
  32.                 a = Num_A.Value;
  33.                 b = Num_B.Value;
  34.                 c = Num_C.Value;
  35.                 if (a == 0)
  36.                     MessageBox.Show("a cannot be 0");
  37.                 else
  38.                 {
  39.                     Delta = b * b - 1 * (4) * (a) * (c);
  40.                     textBox_Solution.Text = "▲ = " + b.ToString() + "² " + "-4 * " + a.ToString() + " * " + c.ToString();
  41.                     textBox_Solution.Text += "\r\n▲ = " + Delta.ToString();
  42.                     Delta_Sqrt = Math.Sqrt((double)Delta);
  43.                     textBox_Solution.Text += "\r\n√" + Delta.ToString() + " = " + Delta_Sqrt.ToString();
  44.                    
  45.                     X_kodkod = (b * (-1)) / (2 * a);            /*חישוב נקודת קודקוד*/
  46.                     Y_kodkod = (Delta * (-1)) / (4 * a);
  47.                     textBox_Kodkod.Text = "( " + X_kodkod.ToString() + ", " + Y_kodkod.ToString() + " )";
  48.                    
  49.                     if (b >= 0)                                 /* חישוב ניגזרת */
  50.                     textBox_Nigzeret.Text = "Y' = " +(2 * a).ToString() + "X + " + b.ToString();
  51.                     else
  52.                     textBox_Nigzeret.Text = "Y' = " + (2 * a).ToString() + "X " + b.ToString();
  53.  
  54.                     if(a > 0)                                  /* עלייה או ירידה */
  55.                     textBox_upORdown.Text = "עולה";
  56.                     if (a < 0)
  57.                     textBox_upORdown.Text = "יורדת";
  58.  
  59.                     if (Delta < 0)                             /* פתירת המשוואה הריבועית */
  60.                     textBox_Solution.Text += "\r\nאין פיתרון!";
  61.                     if (Delta == 0)
  62.                     {
  63.                         textBox_Solution.Text += "\r\nX1,2 = (" + (b * -1).ToString() + " ± 0) /" + (2 * a).ToString();
  64.                         X1 = (b * -1) / (2 * a);
  65.                         textBox_Solution.Text += "\r\nX = " + X1.ToString();
  66.                         textBox_X1.Text = "X1 = " + X1.ToString();
  67.                     }
  68.                     if (Delta > 0)
  69.                     {
  70.                         textBox_Solution.Text += "\r\nX = (" + (b * -1).ToString() + " ± " + Delta_Sqrt.ToString() + ") /" + (2 * a).ToString();
  71.                         Delta_Sqrt1 = (decimal)Delta_Sqrt;
  72.                         X1 = ((b * -1) + Delta_Sqrt1) / (2 * a);
  73.                         X2 = ((b * -1) - Delta_Sqrt1) / (2 * a);
  74.                         textBox_Solution.Text += "\r\nX1 = " + X1.ToString();
  75.                         textBox_X1.Text = "X1 = " + X1.ToString();
  76.                         textBox_Solution.Text += "\r\nX2 = " + X2.ToString();
  77.                         textBox_X2.Text = "X2 = " + X2.ToString();
  78.                     }
  79.  
  80.                     if (a < 0 && Y_kodkod < 0)              /* מציאת תחום שליליות וחיוביות */
  81.                     {
  82.                         textBox_Up_Point.Text = "אין";
  83.                         textBox_Down_Point.Text = "כל X";
  84.                         textBox_Down.Text = "X<" + X_kodkod.ToString("0.###");
  85.                         textBox_Up.Text = "X>" + Y_kodkod.ToString("0.###");
  86.                     }
  87.                     if (a < 0 && Y_kodkod > 0)
  88.                     {
  89.                         textBox_Up_Point.Text = X1.ToString("0.###") + "<X<" + X2.ToString("0.###");
  90.                         textBox_Down_Point.Text = X1.ToString("0.###") + ">X>" + X2.ToString("0.###");
  91.                         textBox_Down.Text = "X<" + X_kodkod.ToString("0.###");
  92.                         textBox_Up.Text = "X>" + Y_kodkod.ToString("0.###");
  93.                     }
  94.                     if (a < 0 && Y_kodkod == 0)
  95.                     {
  96.                         textBox_Up_Point.Text = "אין";
  97.                         textBox_Down_Point.Text = "x<" + X1.ToString("0.###") + "<x";
  98.                         textBox_Down.Text = "X<" + X_kodkod.ToString("0.###");
  99.                         textBox_Up.Text = "X>" + Y_kodkod.ToString("0.###");
  100.                     }
  101.                     if (a > 0 && Y_kodkod > 0)
  102.                     {
  103.                         textBox_Up_Point.Text = "כל X";
  104.                         textBox_Down_Point.Text =  "אין";
  105.                         textBox_Down.Text = "X>" + X_kodkod.ToString("0.###");
  106.                         textBox_Up.Text = "X<" + Y_kodkod.ToString("0.###");
  107.                     }
  108.                     if (a > 0 && Y_kodkod < 0)
  109.                     {
  110.                         textBox_Up_Point.Text = X1.ToString("0.###") + ">X>" + X2.ToString("0.###");
  111.                         textBox_Down_Point.Text = X1.ToString("0.###") + "<X<" + X2.ToString("0.###");
  112.                         textBox_Down.Text = "X>" + X_kodkod.ToString("0.###");
  113.                         textBox_Up.Text = "X<" + Y_kodkod.ToString("0.###");
  114.                     }
  115.                     if (a > 0 && Y_kodkod == 0)
  116.                     {
  117.                         textBox_Up_Point.Text = "x<" + X1.ToString("0.###") + "<x";
  118.                         textBox_Down_Point.Text = "אין";
  119.                         textBox_Down.Text = "X>" + X_kodkod.ToString("0.###");
  120.                         textBox_Up.Text = "X<" + Y_kodkod.ToString("0.###");
  121.                     }
  122.                        
  123.                 }
  124.             }
  125.             catch (Exception ex)
  126.             {
  127.                 MessageBox.Show("Error [ " + ex.Message + " ]");
  128.             }
  129.  
  130.  
  131.         }
  132.  
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment