amarek

OOP LV6 - Zadatak1

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