Latihan 2 PBKK (A)
Nama : Tsaqif Deniar B.
NRP : 5025211151
Kelas : PBKK (A)
LATIHAN 2
Latihan 1 pada kelas PBKK yaitu membuat applikasi kalkulator sederhana dengan menggunakan bahasa C# pada IDE yang dijalankan oleh .NET Framework. Kalkulator berikut memiliki fungsi penjumlahan(+), pengurangan(-), perkalian(x), pembagian(:), seperti kalkulator pada umumnya kita hanya perlu menekan tombol angka dan operasi lalu akan keluar hasil sesuai dengan perhitungan dari kalkulator.
Berikut dokumentasi hasil program :
Berikut source code program :
This file contains 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
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 AppKalkulator | |
{ | |
public partial class Form1 : Form | |
{ | |
decimal bil1; | |
decimal bil2; | |
int opr; | |
Boolean opr_selesai = false; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void textBox1_TextChanged(object sender, EventArgs e) | |
{ | |
} | |
private void btn1_Click(object sender, EventArgs e) | |
{ | |
bil1 = Convert.ToDecimal(TBox1.Text); | |
TBox2.Text = "/"; | |
TBox1.Text = " "; | |
opr = 2; | |
opr_selesai = true; | |
} | |
private void btn5_Click(object sender, EventArgs e) | |
{ | |
if(TBox1.Text == "0") | |
{ | |
TBox1.Text = "1"; | |
} | |
else | |
{ | |
TBox1.Text += "1"; | |
} | |
} | |
private void btn6_Click(object sender, EventArgs e) | |
{ | |
if (TBox1.Text == "0") | |
{ | |
TBox1.Text = "2"; | |
} | |
else | |
{ | |
TBox1.Text += "2"; | |
} | |
} | |
private void btn7_Click(object sender, EventArgs e) | |
{ | |
if (TBox1.Text == "0") | |
{ | |
TBox1.Text = "3"; | |
} | |
else | |
{ | |
TBox1.Text += "3"; | |
} | |
} | |
private void btn9_Click(object sender, EventArgs e) | |
{ | |
if (TBox1.Text == "0") | |
{ | |
TBox1.Text = "4"; | |
} | |
else | |
{ | |
TBox1.Text += "4"; | |
} | |
} | |
private void btn10_Click(object sender, EventArgs e) | |
{ | |
if (TBox1.Text == "0") | |
{ | |
TBox1.Text = "5"; | |
} | |
else | |
{ | |
TBox1.Text += "5"; | |
} | |
} | |
private void btn11_Click(object sender, EventArgs e) | |
{ | |
if (TBox1.Text == "0") | |
{ | |
TBox1.Text = "6"; | |
} | |
else | |
{ | |
TBox1.Text += "6"; | |
} | |
} | |
private void btn13_Click(object sender, EventArgs e) | |
{ | |
if (TBox1.Text == "0") | |
{ | |
TBox1.Text = "7"; | |
} | |
else | |
{ | |
TBox1.Text += "7"; | |
} | |
} | |
private void btn14_Click(object sender, EventArgs e) | |
{ | |
if (TBox1.Text == "0") | |
{ | |
TBox1.Text = "8"; | |
} | |
else | |
{ | |
TBox1.Text += "8"; | |
} | |
} | |
private void btn15_Click(object sender, EventArgs e) | |
{ | |
if (TBox1.Text == "0") | |
{ | |
TBox1.Text = "9"; | |
} | |
else | |
{ | |
TBox1.Text += "9"; | |
} | |
} | |
private void btn16_Click(object sender, EventArgs e) | |
{ | |
if(TBox1.Text != "0") | |
{ | |
TBox1.Text += "0"; | |
} | |
} | |
private void btn8_Click(object sender, EventArgs e) | |
{ | |
TBox1.Text = "0"; | |
bil1 = 0; | |
bil2 = 0; | |
TBox2.Text = " "; | |
} | |
private void btn2_Click(object sender, EventArgs e) | |
{ | |
bil1 = Convert.ToDecimal(TBox1.Text); | |
TBox2.Text = "x"; | |
TBox1.Text = " "; | |
opr = 1; | |
opr_selesai = true; | |
} | |
private void btn3_Click(object sender, EventArgs e) | |
{ | |
bil1 = Convert.ToDecimal(TBox1.Text); | |
TBox2.Text = "-"; | |
TBox1.Text = " "; | |
opr = 3; | |
opr_selesai = true; | |
} | |
private void btn4_Click(object sender, EventArgs e) | |
{ | |
bil1 = Convert.ToDecimal(TBox1.Text); | |
TBox2.Text = "+"; | |
TBox1.Text = " "; | |
opr = 4; | |
opr_selesai = true; | |
} | |
private void btn12_Click(object sender, EventArgs e) | |
{ | |
if (opr_selesai == true) | |
bil2 = Convert.ToDecimal(TBox1.Text); | |
{ | |
switch (opr) | |
{ | |
case 1: | |
TBox1.Text = Convert.ToString(bil1 * bil2); | |
break; | |
case 2: | |
TBox1.Text = Convert.ToString(bil1 / bil2); | |
break; | |
case 3: | |
TBox1.Text = Convert.ToString(bil1 - bil2); | |
break; | |
case 4: | |
TBox1.Text = Convert.ToString(bil1 + bil2); | |
break; | |
} | |
opr_selesai = false; | |
} | |
} | |
} | |
} |
Comments
Post a Comment