Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- namespace WindowsFormsApplicationTest {
- public partial class Form1 : Form {
- public Form1() { InitializeComponent(); }
- private void button1_Click(object sender, EventArgs e) {
- double a = 0, b = 0, c = 0, x = 0, y = 0;
- string badFormat = "Неверный формат!";
- string overflow = "Допущено переполнение!";
- bool bad = false;
- try { a = double.Parse(this.textBox3.Text); }
- catch (FormatException ex) { this.textBox3.Text = badFormat; bad = true; }
- catch (OverflowException ex) { this.textBox3.Text = overflow; bad = true; }
- finally {
- try { b = double.Parse(this.textBox4.Text); }
- catch (FormatException ex) { this.textBox4.Text = badFormat; bad = true; }
- catch (OverflowException ex) { this.textBox4.Text = overflow; bad = true; }
- finally {
- try { c = double.Parse(this.textBox5.Text); }
- catch (FormatException ex) { this.textBox5.Text = badFormat; bad = true; }
- catch (OverflowException ex) { this.textBox5.Text = overflow; bad = true; }
- finally {
- try { x = double.Parse(this.textBox1.Text); }
- catch (FormatException ex) { this.textBox1.Text = badFormat; bad = true; }
- catch (OverflowException ex) { this.textBox1.Text = overflow; bad = true; }
- finally {
- try { y = double.Parse(this.textBox2.Text); }
- catch (FormatException ex) { this.textBox2.Text = badFormat; bad = true; }
- catch (OverflowException ex) { this.textBox2.Text = overflow; bad = true; }
- }
- }
- }
- }
- this.label1.Text = "V = ";
- if (bad) this.label1.Text += "Ошибка в данных!";
- else {
- Function function = new Function(a, b, c, x, y);
- this.label1.Text += function.V;
- }
- }
- }
- public class Function {
- private double a, b, c, x, y;
- private string v;
- public string V { get { return v; } }
- public Function(double a, double b, double c, double x, double y) {
- this.a = a;
- this.b = b;
- this.c = c;
- this.x = x;
- this.y = y;
- this.v = Result();
- }
- private string Result() {
- double sum = a + b + c;
- if (double.IsPositiveInfinity(sum)) return "+Бесконечность";
- else if (double.IsNegativeInfinity(sum)) return "-Бесконечность";
- double result;
- if (this.x - this.y == 0) return "Попытка деления на ноль!";
- if (this.x < 3) result = sum / 2 * Math.Min(this.x, Math.Min(this.y, (this.x + this.y) / (this.x - this.y)));
- else if (this.x > 0 && this.y > 1) result = Math.Min(this.x, this.y);
- result = this.y * sum;
- if (double.IsPositiveInfinity(result)) return "+Бесконечность";
- else if (double.IsNegativeInfinity(result)) return "-Бесконечность";
- return result.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement