Tugas 2 PBKK Kalkulator
Nama : Danar Sodik Priyambodo
NRP : 5025211145
PBKK-A
Tugas 2 PBKK kali ini membuat kalkulator sederhana dengan menggunakan IDE Visual Studio, sebelumnya diharuskan menginstall .NET Framework untuk menjalankan IDE dengan bahasa dasar yaitu C#. Beberapa Fungsi kalkulator sederhana yang bisa di gunakan pada aplikasi sederhana ini misalnya, penjumlahan, pengurangan, perkalian, serta pembagian, User hanya perlu menekan tombol angka pada UI untuk memilih angka, kemudian menekan tombol operasi yang diinginkan, dan dilanjutkan menekan kembali angka yang ingin dilakukan operasi tersebut, step terakhir yaitu menekan tombol sama dengan (=) untuk menampilkan hasilnya, fitur tambahan yaitu, hasil dari operasi tersebut, dapat dilanjutkan dengan melakukan operasi selanjutnya, begitu seterusnya sampai hasil yang diinginkan.
Berikut merupakan source code pada program ini :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Kalkulator | |
{ | |
public partial class Form1 : Form | |
{ | |
decimal num1; | |
decimal num2; | |
int opr; | |
Boolean complete_opr = false; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text != "0") | |
{ | |
textBox1.Text = "0"; | |
} | |
} | |
private void button3_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "1"; | |
} | |
else | |
{ | |
textBox1.Text += "1"; | |
} | |
} | |
private void button4_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "2"; | |
} | |
else | |
{ | |
textBox1.Text += "2"; | |
} | |
} | |
private void button5_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "3"; | |
} | |
else | |
{ | |
textBox1.Text += "3"; | |
} | |
} | |
private void button6_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "4"; | |
} | |
else | |
{ | |
textBox1.Text += "4"; | |
} | |
} | |
private void button7_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "5"; | |
} | |
else | |
{ | |
textBox1.Text += "5"; | |
} | |
} | |
private void button8_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "6"; | |
} | |
else | |
{ | |
textBox1.Text += "6"; | |
} | |
} | |
private void button9_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "7"; | |
} | |
else | |
{ | |
textBox1.Text += "7"; | |
} | |
} | |
private void button10_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "8"; | |
} | |
else | |
{ | |
textBox1.Text += "8"; | |
} | |
} | |
private void button11_Click(object sender, EventArgs e) | |
{ | |
if (textBox1.Text == "0") | |
{ | |
textBox1.Text = "9"; | |
} | |
else | |
{ | |
textBox1.Text += "9"; | |
} | |
} | |
private void button12_Click(object sender, EventArgs e) | |
{ | |
textBox1.Text = "0"; | |
num1 = 0; | |
num2 = 0; | |
textBox2.Text = " "; | |
} | |
private void button14_Click(object sender, EventArgs e) | |
{ | |
num1 = Convert.ToDecimal(textBox1.Text); | |
textBox2.Text = "/"; | |
textBox1.Text = " "; | |
opr = 2; | |
complete_opr = true; | |
} | |
private void button15_Click(object sender, EventArgs e) | |
{ | |
num1 = Convert.ToDecimal(textBox1.Text); | |
textBox2.Text = "x"; | |
textBox1.Text = " "; | |
opr = 1; | |
complete_opr = true; | |
} | |
private void button16_Click(object sender, EventArgs e) | |
{ | |
num1 = Convert.ToDecimal(textBox1.Text); | |
textBox2.Text = "-"; | |
textBox1.Text = " "; | |
opr = 3; | |
complete_opr = true; | |
} | |
private void button17_Click(object sender, EventArgs e) | |
{ | |
num1 = Convert.ToDecimal(textBox1.Text); | |
textBox2.Text = "+"; | |
textBox1.Text = " "; | |
opr = 4; | |
complete_opr = true; | |
} | |
private void button18_Click(object sender, EventArgs e) | |
{ | |
if (complete_opr == true) | |
num2 = Convert.ToDecimal(textBox1.Text); | |
{ | |
switch (opr) | |
{ | |
case 1: | |
textBox1.Text = Convert.ToString(num1 * num2); | |
break; | |
case 2: | |
textBox1.Text = Convert.ToString(num1 / num2); | |
break; | |
case 3: | |
textBox1.Text = Convert.ToString(num1 - num2); | |
break; | |
case 4: | |
textBox1.Text = Convert.ToString(num1 + num2); | |
break; | |
} | |
complete_opr = false; | |
} | |
} | |
private void textBox1_TextChanged(object sender, EventArgs e) | |
{ | |
} | |
private void textBox2_TextChanged(object sender, EventArgs e) | |
{ | |
} | |
} | |
} |
Berikut merupakan Dokumentasi pada program ini :
Komentar
Posting Komentar