TUGAS PERTEMUAN KE-1 [MEMBUAT APLIKASI DESKTOP]

Link Sourcecode

Aplikasi ini adalah kalkulator sederhana yang dirancang menggunakan Windows Forms App Framework .NET dengan bantuan Visual Studio. Tujuan utama aplikasi ini adalah memberikan pengguna kemampuan untuk melakukan operasi matematika dasar seperti penjumlahan, pengurangan, perkalian, dan pembagian.

Fitur Utama:

Aplikasi ini memiliki fitur-fitur berikut :

  1. Memungkinkan pengguna untuk melakukan operasi matematika dasar seperti penjumlahan (+), pengurangan (-), perkalian (*), dan pembagian (/).
  2. Tombol delete untuk menghapus satu karakter dari input.
  3. Tombol C untuk menghapus seluruh input yang telah dimasukkan.
  4. Tombol CE untuk menghapus satu karakter dari input tanpa menghapus keseluruhan input.

User Interface:

Fitur Operasi Matematika Sederhana


Fitur Delete

Source Code Calculator in C#:

namespace calculator
{
public partial class Form1 : Form
{
double resultValue = 0;
string operationPerformed = "";
bool isoOperationPerformed = false;
public Form1()
{
InitializeComponent();
}
private void button_click(object sender, EventArgs e)
{
if (display_res.Text == "0" || (isoOperationPerformed))
display_res.Clear();
isoOperationPerformed = false;
Button button = (Button)sender;
if (button.Text == ".")
{
if (!display_res.Text.Contains("."))
display_res.Text += button.Text;
}
else
{
display_res.Text += button.Text;
}
}
private void operation_click(object sender, EventArgs e)
{
Button button = (Button)sender;
operationPerformed = button.Text;
resultValue = Double.Parse(display_res.Text);
current_op.Text = resultValue + "" + operationPerformed;
isoOperationPerformed = true;
}
private void button17_Click(object sender, EventArgs e)
{
display_res.Text = "0";
resultValue = 0;
}
private void button19_Click(object sender, EventArgs e)
{
display_res.Text = "0";
}
private void button_eq_Click(object sender, EventArgs e)
{
if (operationPerformed == "+")
{
display_res.Text = (resultValue + double.Parse(display_res.Text)).ToString();
}
else if (operationPerformed == "-")
{
display_res.Text = (resultValue - double.Parse(display_res.Text)).ToString();
}
else if (operationPerformed == "x")
{
display_res.Text = (resultValue * double.Parse(display_res.Text)).ToString();
}
else
{
display_res.Text = (resultValue / double.Parse(display_res.Text)).ToString();
}
}
private void button_del_Click(object sender, EventArgs e)
{
if (display_res.Text.Length > 0)
display_res.Text = display_res.Text.Remove(display_res.Text.Length - 1, 1);
if (display_res.Text == "")
display_res.Text = "0";
}
}
}
view raw calculator hosted with ❤ by GitHub

Comments

Popular Posts