Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Zadaci
- // 1. zadatak
- namespace LV6
- {
- 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();
- }
- }
- }
- // 2. zadatak
- namespace LV6___Zadatak_2
- {
- public partial class form_imenik : Form
- {
- public form_imenik()
- {
- InitializeComponent();
- }
- class Kontakt
- {
- #region data_members
- private string ime;
- public string prezime;
- private string broj_telefona;
- #endregion
- #region public_methods
- public Kontakt()
- {
- ime = ""; prezime = ""; broj_telefona = "";
- }
- public Kontakt(string i, string p, string b)
- {
- ime = i; prezime = p; broj_telefona = b;
- }
- public override string ToString()
- {
- return ime + "\t" + prezime + "\t" + broj_telefona;
- }
- #endregion
- }
- List<Kontakt> listKontakt = new List<Kontakt>();
- string path = "C:\\Users\\Student\\Documents\\Visual Studio 2015\\Projects\\LV6 - Zadatak 2\\LV6 - Zadatak 2\\imenik.txt";
- private void form_imenik_Load(object sender, EventArgs e)
- {
- using (System.IO.StreamReader reader = new System.IO.StreamReader(@path))
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- string[] parts = line.Split('\t');
- Kontakt K = new Kontakt(parts[0], parts[1], parts[2]);
- listKontakt.Add(K);
- }
- listBox_popis.DataSource = null;
- listBox_popis.DataSource = listKontakt;
- }
- }
- private void button_dodaj_Click(object sender, EventArgs e)
- {
- bool error = false;
- if (textBox_ime.Text == "" || textBox_prezime.Text == "" || textBox_broj.Text == "")
- {
- error = true;
- MessageBox.Show("Neko od polja ostalo je prazno.", "Pogreška!");
- }
- else if (!Regex.IsMatch(textBox_broj.Text, @"^[0-9]+$"))
- {
- error = true;
- MessageBox.Show("Broj telefona je neispravan!", "Pogreška!");
- }
- else
- {
- error = false;
- }
- if (!error)
- {
- Kontakt K = new Kontakt(textBox_ime.Text, textBox_prezime.Text, textBox_broj.Text);
- listKontakt.Add(K);
- listBox_popis.DataSource = null;
- listBox_popis.DataSource = listKontakt;
- textBox_ime.Text = String.Empty;
- textBox_prezime.Text = String.Empty;
- textBox_broj.Text = String.Empty;
- }
- }
- private void button_izlaz_Click(object sender, EventArgs e)
- {
- using (System.IO.StreamWriter write = new System.IO.StreamWriter(@path))
- {
- foreach (Kontakt K in listKontakt)
- {
- {
- write.WriteLine(K.ToString());
- }
- }
- }
- Application.Exit();
- }
- private void button_pretraga_Click(object sender, EventArgs e)
- {
- bool state = false;
- if (textBox_pretraga.Text == "")
- {
- MessageBox.Show("Niste unjeli prezime!", "Pogreška!");
- }
- else
- {
- foreach (Kontakt K in listKontakt)
- {
- if (K.prezime.Contains(textBox_pretraga.Text))
- {
- state = true;
- break;
- }
- else
- {
- state = false;
- }
- }
- if (state)
- {
- MessageBox.Show("Kontakt postoji!", "Pretraga!");
- }
- else
- {
- MessageBox.Show("Kontakt ne postoji!", "Pretraga!");
- }
- }
- }
- }
- }
- // Analiza
- // 1. Napravite aplikaciju znanstveni kalkulator koja će imati funkcionalnost
- // znanstvenog kalkulatora, odnosno implementirati osnovne (+,-,*,/) i barem 5
- // naprednih (sin, cos, log, sqrt...) operacija.
- namespace LV6___Analiza_1
- {
- public partial class form_kalkulator : Form
- {
- double FirstNumber;
- string Operation;
- public form_kalkulator()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "0" && textBox_display.Text != null)
- {
- textBox_display.Text = "1";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "1";
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "0" && textBox_display.Text != null)
- {
- textBox_display.Text = "2";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "2";
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "0" && textBox_display.Text != null)
- {
- textBox_display.Text = "3";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "3";
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "0" && textBox_display.Text != null)
- {
- textBox_display.Text = "4";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "4";
- }
- }
- private void button5_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "0" && textBox_display.Text != null)
- {
- textBox_display.Text = "5";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "5";
- }
- }
- private void button6_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "0" && textBox_display.Text != null)
- {
- textBox_display.Text = "6";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "6";
- }
- }
- private void button7_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "0" && textBox_display.Text != null)
- {
- textBox_display.Text = "7";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "7";
- }
- }
- private void button8_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "0" && textBox_display.Text != null)
- {
- textBox_display.Text = "8";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "8";
- }
- }
- private void button9_Click(object sender, EventArgs e)
- {
- if (textBox_display.Text == "" && textBox_display.Text != null)
- {
- textBox_display.Text = "9";
- }
- else
- {
- textBox_display.Text = textBox_display.Text + "9";
- }
- }
- private void button0_Click(object sender, EventArgs e)
- {
- textBox_display.Text = textBox_display.Text + "0";
- }
- private void button_dot_Click(object sender, EventArgs e)
- {
- textBox_display.Text = textBox_display.Text + ".";
- }
- private void button_off_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void button_ce_Click(object sender, EventArgs e)
- {
- textBox_display.Text = "0";
- }
- private void button_add_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- textBox_display.Text = "0";
- Operation = "+";
- }
- private void button_sub_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- textBox_display.Text = "0";
- Operation = "-";
- }
- private void button_mul_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- textBox_display.Text = "0";
- Operation = "*";
- }
- private void button_div_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- textBox_display.Text = "0";
- Operation = "/";
- }
- private void button_equal_Click(object sender, EventArgs e)
- {
- double SecondNumber;
- double Result;
- SecondNumber = Convert.ToDouble(textBox_display.Text);
- if (Operation == "+")
- {
- Result = (FirstNumber + SecondNumber);
- textBox_display.Text = Convert.ToString(Result);
- FirstNumber = Result;
- }
- if (Operation == "-")
- {
- Result = (FirstNumber - SecondNumber);
- textBox_display.Text = Convert.ToString(Result);
- FirstNumber = Result;
- }
- if (Operation == "*")
- {
- Result = (FirstNumber * SecondNumber);
- textBox_display.Text = Convert.ToString(Result);
- FirstNumber = Result;
- }
- if (Operation == "/")
- {
- if (SecondNumber == 0)
- {
- textBox_display.Text = "Cannot divide by zero";
- }
- else
- {
- Result = (FirstNumber / SecondNumber);
- textBox_display.Text = Convert.ToString(Result);
- FirstNumber = Result;
- }
- }
- }
- private void button_sqrt_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- double Result = 0;
- Result = Math.Sqrt(FirstNumber);
- textBox_display.Text = Result.ToString();
- }
- private void button_log_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- double Result;
- Result = Math.Log(FirstNumber);
- textBox_display.Text = Result.ToString();
- }
- private void button_sin_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- double Result = 0;
- Result = Math.Sin(FirstNumber);
- textBox_display.Text = Result.ToString();
- }
- private void button_cos_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- double Result = 0;
- Result = Math.Cos(FirstNumber);
- textBox_display.Text = Result.ToString();
- }
- private void button_tan_Click(object sender, EventArgs e)
- {
- FirstNumber = Convert.ToDouble(textBox_display.Text);
- double Result = 0;
- Result = Math.Tan(FirstNumber);
- textBox_display.Text = Result.ToString();
- }
- }
- }
- // 2. Napravite jednostavnu igru vješala. Pojmovi se učitavaju u listu iz datoteke, i u
- // svakoj partiji se odabire nasumični pojam iz liste. Omogućiti svu
- // funkcionalnost koju biste očekivali od takve igre. Nije nužno crtati vješala,
- // dovoljno je na labeli ispisati koliko je pokušaja za odabir slova preostalo.
- namespace LV6___Analiza_2
- {
- public partial class form_vjesalo : Form
- {
- public form_vjesalo()
- {
- InitializeComponent();
- }
- int hit = 0;
- int pokusaji = 8;
- string pojam;
- static Random rnd = new Random();
- List<Label> labels = new List<Label>();
- List<string> pojmovi = new List<string>();
- string path = "C:\\Users\\Đordan\\Documents\\Visual Studio 2013\\Projects\\LV6 - Analiza 2\\LV6 - Analiza 2\\pojmovi.txt";
- private void Form1_Load(object sender, EventArgs e)
- {
- using (System.IO.StreamReader reader = new System.IO.StreamReader(@path))
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- pojmovi.Add(line);
- }
- }
- int r = rnd.Next(pojmovi.Count);
- pojam = (string)pojmovi[r];
- labels = new List<Label>();
- int startX = 80;
- foreach (char c in pojam)
- {
- Label lbl = new Label();
- lbl.Text = "_";
- lbl.Font = new Font(lbl.Font.Name, 20, lbl.Font.Style);
- lbl.Location = new Point(startX, 90);
- lbl.Tag = c.ToString();
- lbl.AutoSize = true;
- this.Controls.Add(lbl);
- labels.Add(lbl);
- startX = lbl.Right;
- }
- }
- private void button_pokusaj_Click(object sender, EventArgs e)
- {
- if (textBox_pokusaj.Text.Length == 0 || textBox_pokusaj.Text.Length > 1)
- {
- textBox_pokusaj.Text = "";
- MessageBox.Show("Pogrešan unos!", "Greška!");
- }
- else
- {
- if (pojam.Contains(textBox_pokusaj.Text))
- {
- for (int i = 0; i < pojam.Length; i++)
- {
- if (pojam.IndexOf(textBox_pokusaj.Text) == pojam.IndexOf(pojam[i]))
- {
- if (labels[i].Text == "_")
- {
- labels[i].Text = textBox_pokusaj.Text;
- hit++;
- }
- else
- {
- MessageBox.Show("Slovo je već unešeno!", "Greška!");
- break;
- }
- }
- }
- textBox_pokusaj.Text = "";
- if (hit == pojam.Length)
- {
- MessageBox.Show("Pobjedio si!", "Pobjeda!");
- Application.Exit();
- }
- }
- else
- {
- if (pokusaji == 1)
- {
- textBox_pokusaj.Text = "";
- pokusaji--;
- label_pokusaji.Text = "Broj preostalih pokusaja: " + pokusaji;
- MessageBox.Show("Izgubio si!", "Poraz!");
- Application.Exit();
- }
- else
- {
- textBox_pokusaj.Text = "";
- pokusaji--;
- label_pokusaji.Text = "Broj preostalih pokusaja: " + pokusaji;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement