MainForm.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 calculator
  11. {
  12. public partial class MainForm : Form
  13. {
  14. public MainForm()
  15. {
  16. InitializeComponent();
  17. }
  18. private void btnCalculate_Click(object sender, EventArgs e)
  19. {
  20. double x, y, z;
  21. // Считываем данные
  22. try
  23. {
  24. x = double.Parse(tbInputX.Text);
  25. y = double.Parse(tbInputY.Text);
  26. z = double.Parse(tbInputZ.Text);
  27. } catch (FormatException)
  28. {
  29. MessageBox.Show("Убедитесь, что во всех полях указаны числа в правильном формате!");
  30. return;
  31. }
  32. // Вычисляем ответ
  33. double Output = 0.00d;
  34. try
  35. {
  36. Output += Math.Pow(2, Math.Pow(y, x));
  37. Output += Math.Pow(Math.Pow(3, x), y);
  38. Output -= (y * (Math.Atan(z) - Math.PI / 6)) / (Math.Abs(x) + 1 / (y * y + 1));
  39. } catch (DivideByZeroException)
  40. {
  41. MessageBox.Show("При вычислении ответа необходимо делить на 0!");
  42. return;
  43. }
  44. // Выводим ответ в lblAnswer
  45. lblAnswer.Visible = true;
  46. lblAnswer.Text = Convert.ToString(Output);
  47. }
  48. private void Form1_Load(object sender, EventArgs e)
  49. {
  50. lblAnswer.Visible = false;
  51. }
  52. }
  53. }