Tugas 1 PBKK Membuat Kakulator
NRP : 5025211251
Link github : Repository GitHub
Calculator Sederhana
Di sini saya membuat kalkulator sederhana menggunakan Visual Studio 2022,kalkulator buatan saya berisi beberapa angka,text box, dan beberapa parameter seperti penjumlahan,pengurangan,perkalian,dan pembagian. berikut adalah gambar dari calculator saya
Selanjutnya saya akan mendemonstrasikan beberapa fungsi yang bisa di lakukan dengan kalkulator buatan saya
- Penjumlahan
Penjumlahan bisa di lakukan dengan memilih angka yang diinginkan lalu menekan tombol "+" dan memilih angka yang ingin di tambahkan, berikut adalah contoh dan hasil dari penjumlahan menggunakan kalkulator buatan saya :
- Pengurangan
Pengurangan bisa di lakukan dengan memilih angka yang diinginkan lalu menekan tombol "-" dan memilih angka yang menjadi pengurangnya, berikut adalah contoh dan hasil dari pengurangan menggunakan kalkulator buatan saya :
- Perkalian
Perkalian bisa di lakukan dengan memilih angka yang diinginkan lalu menekan tombol "x" dan memilih angka yang menjadi pengalinya, berikut adalah contoh dan hasil dari perkalian menggunakan kalkulator buatan saya :
- Pembagian
Pembagian bisa di lakukan dengan memilih angka yang diinginkan lalu menekan tombol "/" dan memilih angka yang menjadi pembaginya, berikut adalah contoh dan hasil dari pembagian menggunakan kalkulator buatan saya :
Source code
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Calculator
{
public partial class Form1 : Form
{
decimal bil1;
decimal bil2;
int opr;
Boolean opr_selesai = false;
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "1";
}
else
{
textBox1.Text += "1";
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "2";
}
else
{
textBox1.Text += "2";
}
}
private void button3_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 button11_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "7";
}
else
{
textBox1.Text += "7";
}
}
private void button12_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "8";
}
else
{
textBox1.Text += "8";
}
}
private void button13_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
textBox1.Text = "9";
}
else
{
textBox1.Text += "9";
}
}
private void button16_Click(object sender, EventArgs e)
{
if (textBox1.Text != "0")
{
textBox1.Text += "0";
}
}
private void button15_Click(object sender, EventArgs e)
{
textBox1.Text = "0" ;
bil1 = 0;
bil2 = 0;
textBox2.Text = "" ;
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox2.Text == "0")
{
textBox2.Text = "+";
}
bil1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "+";
textBox1.Text = "";
opr = 1;
opr_selesai = true;
}
private void button5_Click(object sender, EventArgs e)
{
if (textBox2.Text == "0")
{
textBox2.Text = "-";
}
bil1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "-";
textBox1.Text = "";
opr = 2;
opr_selesai = true;
}
private void button9_Click(object sender, EventArgs e)
{
if (textBox2.Text == "0")
{
textBox2.Text = "X";
}
bil1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "X";
textBox1.Text = "";
opr = 3;
opr_selesai = true;
}
private void button10_Click(object sender, EventArgs e)
{
if (textBox2.Text == "0")
{
textBox2.Text = "/";
}
bil1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "/";
textBox1.Text = "";
opr = 4;
opr_selesai = true;
}
private void button14_Click(object sender, EventArgs e)
{
if (textBox2.Text == "0")
{
textBox2.Text = "%";
}
bil1 = Convert.ToDecimal(textBox1.Text);
textBox2.Text = "%";
textBox1.Text = "";
opr = 5;
opr_selesai = true;
}
private void button17_Click(object sender, EventArgs e)
{
if (opr_selesai == true)
{
bil2 = Convert.ToDecimal(textBox1.Text);
switch(opr)
{
case 1:
textBox1.Text = Convert.ToString(bil1 + bil2);
break;
case 2:
textBox1.Text = Convert.ToString(bil1 - bil2);
break;
case 3:
textBox1.Text = Convert.ToString(bil1 * bil2);
break;
case 4:
textBox1.Text = Convert.ToString(bil1 / bil2);
break;
case 5:
textBox1.Text = Convert.ToString(bil1 / 100 );
break;
}
textBox2.Text = "";
opr_selesai = false;
}
}
}
}
Komentar
Posting Komentar