Advertisement
Guest User

Калкулатор на дроби - опростен

a guest
Jan 12th, 2022
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: Admin
  4.  * Date: 12.1.2022 г.
  5.  * Time: 13:02
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Drawing;
  12. using System.Windows.Forms;
  13.  
  14. namespace drobi
  15. {
  16.     /// <summary>
  17.     /// Description of MainForm.
  18.     /// </summary>
  19.     public partial class MainForm : Form
  20.     {
  21.         public MainForm()
  22.         {
  23.             //
  24.             // The InitializeComponent() call is required for Windows Forms designer support.
  25.             //
  26.             InitializeComponent();
  27.            
  28.             //
  29.             // TODO: Add constructor code after the InitializeComponent() call.
  30.             //
  31.         }
  32.         void RadioButtonPlusCheckedChanged(object sender, EventArgs e)
  33.         {
  34.             labelSign.Text = "+";
  35.         }
  36.         void RadioButtonMinusCheckedChanged(object sender, EventArgs e)
  37.         {
  38.             labelSign.Text = "-";
  39.         }
  40.         void RadioButtonPoCheckedChanged(object sender, EventArgs e)
  41.         {
  42.             labelSign.Text = "*";
  43.         }
  44.         void RadioButtonDelCheckedChanged(object sender, EventArgs e)
  45.         {
  46.             labelSign.Text = "/";
  47.         }
  48.        
  49.         void ButtonCalculateClick(object sender, EventArgs e)
  50.         {
  51.             int a = 0;
  52.             int b = 0;
  53.             int c = 0;
  54.             int d = 0;
  55.             int x, y;
  56.            
  57.             try
  58.             {
  59.                 a = int.Parse(textBoxA.Text);
  60.                 b = int.Parse(textBoxB.Text);
  61.                 c = int.Parse(textBoxC.Text);
  62.                 d = int.Parse(textBoxD.Text);
  63.             }
  64.             catch
  65.             {              
  66.                 MessageBox.Show("Некоректни входни данни");
  67.                 return;
  68.             }
  69.            
  70.             if (labelSign.Text == "?")
  71.             {
  72.                 MessageBox.Show("Изберете действие");
  73.                 return;
  74.             }
  75.            
  76.             if (labelSign.Text == "+")
  77.             {
  78.                 x = a * d + b * c;
  79.                 y = b * d;
  80.                 labelX.Text = x.ToString();
  81.                 labelY.Text = y.ToString();            
  82.             }
  83.             else if (labelSign.Text == "-")
  84.             {
  85.                 x = a * d - b * c;
  86.                 y = b * d;
  87.                 labelX.Text = x.ToString();
  88.                 labelY.Text = y.ToString();            
  89.             }
  90.             else if (labelSign.Text == "*")
  91.             {
  92.                 x = a * c;
  93.                 y = b * d;
  94.                 labelX.Text = x.ToString();
  95.                 labelY.Text = y.ToString();
  96.             }
  97.             else if (labelSign.Text == "/")
  98.             {
  99.                 x = a * d;
  100.                 y = b * c;
  101.                 labelX.Text = x.ToString();
  102.                 labelY.Text = y.ToString();
  103.             }
  104.            
  105.         }
  106.     }
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement