Advertisement
vvvaaalll

OOP_LV6_zad1

Dec 16th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.14 KB | None | 0 0
  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.  
  11. namespace zad1
  12. {
  13.     public partial class form_trokut : Form
  14.     {
  15.         double a, b, c;
  16.         public form_trokut()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         double povrsina()
  22.         {
  23.             double s = (a + b + c) / 2;
  24.             return System.Math.Round(System.Math.Sqrt(s * (s - a) * (s - b) * (s - c)), 2);
  25.         }
  26.  
  27.         double opseg()
  28.         {
  29.             return System.Math.Round((a + b + c), 2);
  30.         }
  31.  
  32.         bool pravokutan()
  33.         {
  34.             if (c == System.Math.Sqrt(a * a + b * b))
  35.             {
  36.                 return true;
  37.             }
  38.             return false;
  39.         }
  40.  
  41.         private void button_izracunaj_Click(object sender, EventArgs e)
  42.         {
  43.             if (!double.TryParse(textBox_a.Text, out a))
  44.             {
  45.                 MessageBox.Show("Pogrešan unos stranice a!", "Pogreška!");
  46.             }
  47.             else if (!double.TryParse(textBox_b.Text, out b))
  48.             {
  49.                 MessageBox.Show("Pogrešan unos stranice b!", "Pogreška!");
  50.             }
  51.             else if (!double.TryParse(textBox_c.Text, out c))
  52.             {
  53.                 MessageBox.Show("Pogrešan unos stranice c!", "Pogreška!");
  54.             }
  55.             else if (c >= a + b || b >= a + c || a >= b + c)
  56.             {
  57.                 MessageBox.Show("Trokut nije moguć!", "Pogreška!");
  58.             }
  59.             else
  60.             {
  61.                 label_povrsina.Text = ("Površina: " + povrsina()).ToString();
  62.                 label_opseg.Text = ("Opseg: " + opseg()).ToString();
  63.             }
  64.         }
  65.  
  66.         private void button_pravokutan_Click(object sender, EventArgs e)
  67.         {
  68.             if (!double.TryParse(textBox_a.Text, out a))
  69.             {
  70.                 MessageBox.Show("Pogrešan unos stranice a!", "Pogreška!");
  71.             }
  72.             else if (!double.TryParse(textBox_b.Text, out b))
  73.             {
  74.                 MessageBox.Show("Pogrešan unos stranice b!", "Pogreška!");
  75.             }
  76.             else if (!double.TryParse(textBox_c.Text, out c))
  77.             {
  78.                 MessageBox.Show("Pogrešan unos stranice c!", "Pogreška!");
  79.             }
  80.             else if (c >= a + b || b >= a + c || a >= b + c)
  81.             {
  82.                 MessageBox.Show("Trokut nije moguć!", "Pogreška!");
  83.             }
  84.             else
  85.             {
  86.                 if (pravokutan())
  87.                 {
  88.                     label_pravokutan.ForeColor = System.Drawing.Color.Green;
  89.                     label_pravokutan.Text = "Pravokutan: DA";
  90.                 }
  91.                 else
  92.                 {
  93.                     label_pravokutan.ForeColor = System.Drawing.Color.Red;
  94.                     label_pravokutan.Text = "Pravokutan: NE";
  95.                 }
  96.             }
  97.         }
  98.  
  99.         private void button_izlaz_Click(object sender, EventArgs e)
  100.         {
  101.             Application.Exit();
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement