Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. Napravite aplikaciju znanstveni kalkulator koja će imati funkcionalnost
- // znanstvenog kalkulatora, odnosno implementirati osnovne (+,-,*,/) i barem 5
- // naprednih (sin, cos, log, sqrt...) operacija.
- 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 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.
- 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 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