using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace calculator { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } /// /// Вычисляет ответ задания /// /// Переменная x /// Переменная y /// Переменная z /// Указатель на переменную успеха /// Ответ задания public double CalculateAnswer(double x, double y, double z, ref bool success) { Console.Write(y); double output = 0.00d; try { output += Math.Pow(2, Math.Pow(y, x)); output += Math.Pow(Math.Pow(3, x), y); output -= (y * (Math.Atan(z) - Math.PI / 6)) / (Math.Abs(x) + 1 / (y * y - 1)); success = true; } catch (DivideByZeroException) { success = false; } return output; } /// /// Клик кнопки, вычисляющей ответ /// /// /// private void btnCalculate_Click(object sender, EventArgs e) { double x, y, z; // Считываем данные try { x = double.Parse(tbInputX.Text); y = double.Parse(tbInputY.Text); z = double.Parse(tbInputZ.Text); } catch (FormatException) { MessageBox.Show("Убедитесь, что во всех полях указаны числа в правильном формате!"); return; } // Вычисляем ответ bool success = false; double answer = CalculateAnswer(x, y, z, ref success); if (success) { // Выводим ответ в lblAnswer lblAnswer.Visible = true; lblAnswer.Text = Convert.ToString(answer); } else { MessageBox.Show("При вычислении ответа произошла ошибка!"); } } /// /// Метод загрузки главной формы /// /// /// private void MainForm_Load(object sender, EventArgs e) { lblAnswer.Visible = false; } } }