CalculatorMain.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace RadioCalculator
  11. {
  12. public partial class CalculatorMain : Form
  13. {
  14. public CalculatorMain()
  15. {
  16. InitializeComponent();
  17. }
  18. private void CalcMainLoad(object sender, EventArgs e)
  19. {
  20. lblAnswer.Visible = false;
  21. }
  22. private void btnCalculate_Click(object sender, EventArgs e)
  23. {
  24. // Считываем значения, проверяем правильность
  25. float x, y, z, Output;
  26. try
  27. {
  28. x = float.Parse(tbInputX.Text);
  29. y = float.Parse(tbInputY.Text);
  30. z = float.Parse(tbInputZ.Text);
  31. }
  32. catch (FormatException)
  33. {
  34. MessageBox.Show("Убедитесь, что во всех полях указаны числа в правильном формате!");
  35. return;
  36. }
  37. // Вычисляем ответ
  38. // Значение функции f(x)
  39. float FunctionOutput;
  40. try
  41. {
  42. if (rbFunctionSh.Checked)
  43. {
  44. FunctionOutput = MathF.Sinh(x);
  45. }
  46. else if (rbFunctionPow2.Checked)
  47. {
  48. FunctionOutput = (float)Math.Pow(x, 2);
  49. }
  50. else
  51. {
  52. FunctionOutput = (float)Math.Pow(Math.E, x);
  53. }
  54. // Значение выражения
  55. Output = Math.Min(FunctionOutput + y, y - z) / Math.Max(FunctionOutput, y);
  56. } catch (Exception ex)
  57. {
  58. MessageBox.Show($"Возникла ошибка при вычислении выражения! ({ex.Message})");
  59. return;
  60. }
  61. // Записываем ответ в надпись
  62. lblAnswer.Visible = true;
  63. lblAnswer.Text = Convert.ToString(Output);
  64. }
  65. }
  66. }