PBKK B - TUGAS 1

PBKK B - TUGAS 1 - Membuat Kalkulator Sederhana

Nama : Azhar Abiyu Rasendriya H
Kelas : PBKK B
NRP   : 5025211177

LATIHAN TUGAS 1
Pada tugas pertama ini, tugasnya adalah membuat kalkulator sederhana menggunakan Microsoft Visual Studio 2022 dan bahasa pemrograman C#. Sebelum memulai tugas ini, dapat mendownload .NET Framework serta Microsoft Visual Studio yang telah tersedia.

Kalkulator sederhana yang dibuat memiliki angka 0 hingga 9 untuk memasukkan angka, dan juga dilengkapi dengan operasi matematika seperti pembagian, penjumlahan, perkalian, dan pengurangan. Terdapat tombol "=" untuk menampilkan hasil dari perhitungan antara angka pertama dan angka kedua.

Selain itu, terdapat tombol "C" yang berfungsi untuk membersihkan atau menghapus semua angka dan operasi yang telah dimasukkan sebelumnya.

Seluruh operasi kalkulator ditampilkan pada dua elemen berikut:

TextBox 1: Untuk menampilkan angka yang dimasukkan dan hasil perhitungan.

TextBox 2: Untuk menampilkan operasi matematika yang sedang berlangsung.

Dokumentasi dari kalkulator yang dibuat akan memperlihatkan antarmuka pengguna dan fungsionalitas kalkulator yang telah dijelaskan di atas.


Source code :
namespace Kalkulator
{
public partial class Form1 : Form
{
decima bilangan1;
decimal bilangan2;
int opr;
Boolean opr_selesai = false;
public Form1()
{
InitializeComponent();
}
private void angka0_Click(object sender, EventArgs e)
{
if (textBox1.Text != "0")
{
textBox1.Text = "0";
}
}
private void angka1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "1";
}
else
{
textBox1.Text += "1";
}
}
private void angka2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "2";
}
else
{
textBox1.Text += "2";
}
}
private void angka3_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "3";
}
else
{
textBox1.Text += "3";
}
}
private void angka4_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "4";
}
else
{
textBox1.Text += "4";
}
}
private void angka5_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "5";
}
else
{
textBox1.Text += "5";
}
}
private void angak6_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "6";
}
else
{
textBox1.Text += "6";
}
}
private void angka7_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "7";
}
else
{
textBox1.Text += "7";
}
}
private void angka8_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "8";
}
else
{
textBox1.Text += "8";
}
}
private void angka9_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "9";
}
else
{
textBox1.Text += "9";
}
}
private void tombolclear_Click(object sender, EventArgs e)
{
textBox1.Text = "0";
bilangan1 = 0;
bilangan2 = 0;
textBox2.Text = " ";
}
private void bagi_Click(object sender, EventArgs e)
{
bilangan1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "/";
textBox1.Text = " ";
opr = 2;
opr_selesai = true;
}
private void kali_Click(object sender, EventArgs e)
{
bilangan1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "x";
textBox1.Text = " ";
opr = 1;
opr_selesai = true;
}
private void kurang_Click(object sender, EventArgs e)
{
bilangan1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "-";
textBox1.Text = " ";
opr = 3;
opr_selesai = true;
}
private void tambah_Click(object sender, EventArgs e)
{
bilangan1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "+";
textBox1.Text = " ";
opr = 4;
opr_selesai = true;
}
private void samadengan_Click(object sender, EventArgs e)
{
if (opr_selesai == true)
bilangan2 = Convert.ToDecimal(textBox1.Text);
{
switch (opr)
{
case 1:
textBox1.Text = Convert.ToString(bilangan1 * bilangan2);
break;
case 2:
textBox1.Text = Convert.ToString(bilangan1 / bilangan2);
break;
case 3:
textBox1.Text = Convert.ToString(bilangan1 - bilangan2);
break;
case 4:
textBox1.Text = Convert.ToString(bilangan1 + bilangan2);
break;
}
opr_selesai = false;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}


Komentar

Postingan populer dari blog ini

TUGAS 02 - Analisis dan Perancangan Sistem Informasi E

EAS - Analisis dan Perancangan Sistem Informasi E

PWEB A - ETS