Advertisement
amarek

LV6 - Zad1

Jan 8th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.82 KB | None | 0 0
  1. /* 1. Napravite aplikaciju znanstveni kalkulator koja će imati funkcionalnost
  2. znanstvenog kalkulatora, odnosno implementirati osnovne (+,-,*,/) i barem 5
  3. naprednih (sin, cos, log, sqrt...) operacija.*/
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14.  
  15. namespace LV6
  16. {
  17.     public partial class form_kalkulator : Form
  18.     {
  19.         double PrviBr;
  20.         string Operacija;
  21.  
  22.         public form_kalkulator()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void button_br1_Click(object sender, EventArgs e)
  28.         {
  29.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  30.             {
  31.                 textBox_display.Text = "1";
  32.             }
  33.             else
  34.             {
  35.                 textBox_display.Text = textBox_display.Text + "1";
  36.             }
  37.         }
  38.  
  39.         private void button_br2_Click(object sender, EventArgs e)
  40.         {
  41.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  42.             {
  43.                 textBox_display.Text = "2";
  44.             }
  45.             else
  46.             {
  47.                 textBox_display.Text = textBox_display.Text + "2";
  48.             }
  49.         }
  50.  
  51.         private void button_br3_Click(object sender, EventArgs e)
  52.         {
  53.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  54.             {
  55.                 textBox_display.Text = "3";
  56.             }
  57.             else
  58.             {
  59.                 textBox_display.Text = textBox_display.Text + "3";
  60.             }
  61.         }
  62.  
  63.         private void button_br4_Click(object sender, EventArgs e)
  64.         {
  65.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  66.             {
  67.                 textBox_display.Text = "4";
  68.             }
  69.             else
  70.             {
  71.                 textBox_display.Text = textBox_display.Text + "4";
  72.             }
  73.         }
  74.  
  75.         private void button_br5_Click(object sender, EventArgs e)
  76.         {
  77.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  78.             {
  79.                 textBox_display.Text = "5";
  80.             }
  81.             else
  82.             {
  83.                 textBox_display.Text = textBox_display.Text + "5";
  84.             }
  85.         }
  86.  
  87.         private void button_br6_Click(object sender, EventArgs e)
  88.         {
  89.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  90.             {
  91.                 textBox_display.Text = "6";
  92.             }
  93.             else
  94.             {
  95.                 textBox_display.Text = textBox_display.Text + "6";
  96.             }
  97.         }
  98.  
  99.         private void button_br7_Click(object sender, EventArgs e)
  100.         {
  101.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  102.             {
  103.                 textBox_display.Text = "7";
  104.             }
  105.             else
  106.             {
  107.                 textBox_display.Text = textBox_display.Text + "7";
  108.             }
  109.         }
  110.  
  111.         private void button_br8_Click(object sender, EventArgs e)
  112.         {
  113.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  114.             {
  115.                 textBox_display.Text = "8";
  116.             }
  117.             else
  118.             {
  119.                 textBox_display.Text = textBox_display.Text + "8";
  120.             }
  121.         }
  122.  
  123.         private void button_br9_Click(object sender, EventArgs e)
  124.         {
  125.             if (textBox_display.Text == "0" && textBox_display.Text != null)
  126.             {
  127.                 textBox_display.Text = "9";
  128.             }
  129.             else
  130.             {
  131.                 textBox_display.Text = textBox_display.Text + "9";
  132.             }
  133.         }
  134.  
  135.         private void button_br0_Click(object sender, EventArgs e)
  136.         {
  137.             textBox_display.Text = textBox_display.Text + "0";
  138.         }
  139.  
  140.         private void button_tocka_Click(object sender, EventArgs e)
  141.         {
  142.             textBox_display.Text = textBox_display.Text + ".";
  143.         }
  144.  
  145.         private void button_off_Click(object sender, EventArgs e)
  146.         {
  147.             Application.Exit();
  148.         }
  149.  
  150.         private void button_C_Click(object sender, EventArgs e)
  151.         {
  152.             textBox_display.Text = "0";
  153.         }
  154.  
  155.         private void button_plus_Click(object sender, EventArgs e)
  156.         {
  157.             PrviBr = Convert.ToDouble(textBox_display.Text);
  158.             textBox_display.Text = "0";
  159.             Operacija = "+";
  160.         }
  161.  
  162.         private void button_minus_Click(object sender, EventArgs e)
  163.         {
  164.             PrviBr = Convert.ToDouble(textBox_display.Text);
  165.             textBox_display.Text = "0";
  166.             Operacija = "-";
  167.         }
  168.  
  169.         private void button_umnozak_Click(object sender, EventArgs e)
  170.         {
  171.             PrviBr = Convert.ToDouble(textBox_display.Text);
  172.             textBox_display.Text = "0";
  173.             Operacija = "*";
  174.         }
  175.  
  176.         private void button_kvocijent_Click(object sender, EventArgs e)
  177.         {
  178.             PrviBr = Convert.ToDouble(textBox_display.Text);
  179.             textBox_display.Text = "0";
  180.             Operacija = "/";
  181.         }
  182.  
  183.         private void button_jednako_Click(object sender, EventArgs e)
  184.         {
  185.             double DrugiBr;
  186.             double Rez;
  187.  
  188.             DrugiBr = Convert.ToDouble(textBox_display.Text);
  189.  
  190.             if (Operacija == "+")
  191.             {
  192.                 Rez = (PrviBr + DrugiBr);
  193.                 textBox_display.Text = Convert.ToString(Rez);
  194.                 PrviBr = Rez;
  195.             }
  196.             if (Operacija == "-")
  197.             {
  198.                 Rez = (PrviBr - DrugiBr);
  199.                 textBox_display.Text = Convert.ToString(Rez);
  200.                 PrviBr = Rez;
  201.             }
  202.             if (Operacija == "*")
  203.             {
  204.                 Rez = (PrviBr * DrugiBr);
  205.                 textBox_display.Text = Convert.ToString(Rez);
  206.                 PrviBr = Rez;
  207.             }
  208.             if (Operacija == "/")
  209.             {
  210.                 if (DrugiBr == 0)
  211.                 {
  212.                     textBox_display.Text = "Nemoguce dijeliti s nulom";
  213.  
  214.                 }
  215.                 else
  216.                 {
  217.                     Rez = (PrviBr / DrugiBr);
  218.                     textBox_display.Text = Convert.ToString(Rez);
  219.                     PrviBr = Rez;
  220.                 }
  221.             }
  222.         }
  223.  
  224.         private void button_korijen_Click(object sender, EventArgs e)
  225.         {
  226.             PrviBr = Convert.ToDouble(textBox_display.Text);
  227.             double Rez = 0;
  228.             Rez = Math.Sqrt(PrviBr);
  229.             textBox_display.Text = Rez.ToString();
  230.         }
  231.  
  232.         private void button_log_Click(object sender, EventArgs e)
  233.         {
  234.             PrviBr = Convert.ToDouble(textBox_display.Text);
  235.             double Rez;
  236.             Rez = Math.Log(PrviBr);
  237.             textBox_display.Text = Rez.ToString();
  238.         }
  239.  
  240.         private void button_sin_Click(object sender, EventArgs e)
  241.         {
  242.             PrviBr = Convert.ToDouble(textBox_display.Text);
  243.             double Rez = 0;
  244.             Rez = Math.Sin(PrviBr);
  245.             textBox_display.Text = Rez.ToString();
  246.         }
  247.  
  248.         private void button_cos_Click(object sender, EventArgs e)
  249.         {
  250.             PrviBr = Convert.ToDouble(textBox_display.Text);
  251.             double Rez = 0;
  252.             Rez = Math.Cos(PrviBr);
  253.             textBox_display.Text = Rez.ToString();
  254.         }
  255.  
  256.         private void button_tan_Click(object sender, EventArgs e)
  257.         {
  258.             PrviBr = Convert.ToDouble(textBox_display.Text);
  259.             double Rez = 0;
  260.             Rez = Math.Tan(PrviBr);
  261.             textBox_display.Text = Rez.ToString();
  262.         }
  263.     }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement