Advertisement
NickAndNick

183354287

Oct 18th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. namespace WindowsFormsApplicationTest {
  4.     public partial class Form1 : Form  {
  5.         public Form1() { InitializeComponent(); }
  6.         private void button1_Click(object sender, EventArgs e) {
  7.             double a = 0, b = 0, c = 0, x = 0, y = 0;
  8.             string badFormat = "Неверный формат!";
  9.             string overflow = "Допущено переполнение!";
  10.             bool bad = false;
  11.             try { a = double.Parse(this.textBox3.Text); }
  12.             catch (FormatException ex) { this.textBox3.Text = badFormat; bad = true; }
  13.             catch (OverflowException ex) { this.textBox3.Text = overflow; bad = true; }
  14.             finally {
  15.                 try { b = double.Parse(this.textBox4.Text); }
  16.                 catch (FormatException ex) { this.textBox4.Text = badFormat; bad = true; }
  17.                 catch (OverflowException ex) { this.textBox4.Text = overflow; bad = true; }
  18.                 finally {
  19.                     try { c = double.Parse(this.textBox5.Text); }
  20.                     catch (FormatException ex) { this.textBox5.Text = badFormat; bad = true; }
  21.                     catch (OverflowException ex) { this.textBox5.Text = overflow; bad = true; }
  22.                     finally {
  23.                         try { x = double.Parse(this.textBox1.Text); }
  24.                         catch (FormatException ex) { this.textBox1.Text = badFormat; bad = true; }
  25.                         catch (OverflowException ex) { this.textBox1.Text = overflow; bad = true; }
  26.                         finally {
  27.                             try { y = double.Parse(this.textBox2.Text); }
  28.                             catch (FormatException ex) { this.textBox2.Text = badFormat; bad = true; }
  29.                             catch (OverflowException ex) { this.textBox2.Text = overflow; bad = true; }
  30.                         }
  31.                     }
  32.                 }
  33.             }
  34.             this.label1.Text = "V = ";
  35.             if (bad) this.label1.Text += "Ошибка в данных!";
  36.             else {
  37.                 Function function = new Function(a, b, c, x, y);
  38.                 this.label1.Text += function.V;
  39.             }
  40.         }
  41.     }
  42.     public class Function {
  43.         private double a, b, c, x, y;
  44.         private string v;
  45.         public string V { get { return v; } }
  46.         public Function(double a, double b, double c, double x, double y) {
  47.             this.a = a;
  48.             this.b = b;
  49.             this.c = c;
  50.             this.x = x;
  51.             this.y = y;
  52.             this.v = Result();
  53.         }
  54.         private string Result() {
  55.             double sum = a + b + c;
  56.             if (double.IsPositiveInfinity(sum)) return "+Бесконечность";
  57.             else if (double.IsNegativeInfinity(sum)) return "-Бесконечность";
  58.             double result;
  59.             if (this.x - this.y == 0) return "Попытка деления на ноль!";
  60.             if (this.x < 3) result = sum / 2 * Math.Min(this.x, Math.Min(this.y, (this.x + this.y) / (this.x - this.y)));
  61.             else if (this.x > 0 && this.y > 1) result = Math.Min(this.x, this.y);
  62.             result = this.y * sum;
  63.             if (double.IsPositiveInfinity(result)) return "+Бесконечность";
  64.             else if (double.IsNegativeInfinity(result)) return "-Бесконечность";
  65.             return result.ToString();
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement