Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 zad1
- {
- public partial class form_trokut : Form
- {
- double a, b, c;
- public form_trokut()
- {
- InitializeComponent();
- }
- double povrsina()
- {
- double s = (a + b + c) / 2;
- return System.Math.Round(System.Math.Sqrt(s * (s - a) * (s - b) * (s - c)), 2);
- }
- double opseg()
- {
- return System.Math.Round((a + b + c), 2);
- }
- bool pravokutan()
- {
- if (c == System.Math.Sqrt(a * a + b * b))
- {
- return true;
- }
- return false;
- }
- private void button_izracunaj_Click(object sender, EventArgs e)
- {
- if (!double.TryParse(textBox_a.Text, out a))
- {
- MessageBox.Show("Pogrešan unos stranice a!", "Pogreška!");
- }
- else if (!double.TryParse(textBox_b.Text, out b))
- {
- MessageBox.Show("Pogrešan unos stranice b!", "Pogreška!");
- }
- else if (!double.TryParse(textBox_c.Text, out c))
- {
- MessageBox.Show("Pogrešan unos stranice c!", "Pogreška!");
- }
- else if (c >= a + b || b >= a + c || a >= b + c)
- {
- MessageBox.Show("Trokut nije moguć!", "Pogreška!");
- }
- else
- {
- label_povrsina.Text = ("Površina: " + povrsina()).ToString();
- label_opseg.Text = ("Opseg: " + opseg()).ToString();
- }
- }
- private void button_pravokutan_Click(object sender, EventArgs e)
- {
- if (!double.TryParse(textBox_a.Text, out a))
- {
- MessageBox.Show("Pogrešan unos stranice a!", "Pogreška!");
- }
- else if (!double.TryParse(textBox_b.Text, out b))
- {
- MessageBox.Show("Pogrešan unos stranice b!", "Pogreška!");
- }
- else if (!double.TryParse(textBox_c.Text, out c))
- {
- MessageBox.Show("Pogrešan unos stranice c!", "Pogreška!");
- }
- else if (c >= a + b || b >= a + c || a >= b + c)
- {
- MessageBox.Show("Trokut nije moguć!", "Pogreška!");
- }
- else
- {
- if (pravokutan())
- {
- label_pravokutan.ForeColor = System.Drawing.Color.Green;
- label_pravokutan.Text = "Pravokutan: DA";
- }
- else
- {
- label_pravokutan.ForeColor = System.Drawing.Color.Red;
- label_pravokutan.Text = "Pravokutan: NE";
- }
- }
- }
- private void button_izlaz_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement