Kalkulator Sederhana Menggunakan Framework .NET
Pada postingan kali ini, saya mengerjakan contoh aplikasi yang dibuat dengan Framework.NET. Yaitu kalkulator sederhana dengan menggunakan bahasa C# serta MS Visual Studio Code. Dibawah ini adalah code dari pembuatan Kalkulator Sederhana
- 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 Calculator_APP
 - {
 - public partial class Form1 : Form
 - {
 - string first = "";
 - string second = "";
 - char function;
 - double result = 0.0;
 - string userInput = "";
 - public Form1()
 - {
 - InitializeComponent();
 - }
 - private void angka1_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "1";
 - layar.Text += userInput;
 - }
 - private void angka2_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "2";
 - layar.Text += userInput;
 - }
 - private void angka3_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "3";
 - layar.Text += userInput;
 - }
 - private void angka4_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "4";
 - layar.Text += userInput;
 - }
 - private void angka5_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "5";
 - layar.Text += userInput;
 - }
 - private void angka6_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "6";
 - layar.Text += userInput;
 - }
 - private void angka7_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "7";
 - layar.Text += userInput;
 - }
 - private void angka8_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "8";
 - layar.Text += userInput;
 - }
 - private void angka9_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "9";
 - layar.Text += userInput;
 - }
 - private void tombolclear_Click(object sender, EventArgs e)
 - {
 - first = "";
 - second = "";
 - userInput = "";
 - result = 0.0;
 - layar.Text = "0";
 - }
 - private void tombolbagi_Click(object sender, EventArgs e)
 - {
 - function = '/';
 - first = userInput;
 - userInput = "";
 - }
 - private void tombolkali_Click(object sender, EventArgs e)
 - {
 - function = '*';
 - first = userInput;
 - userInput = "";
 - }
 - private void tomboltambah_Click(object sender, EventArgs e)
 - {
 - function = '+';
 - first = userInput;
 - userInput = "";
 - }
 - private void tombolkurang_Click(object sender, EventArgs e)
 - {
 - function = '-';
 - first = userInput;
 - userInput = "";
 - }
 - private void tombolsamadengan_Click(object sender, EventArgs e)
 - {
 - second = userInput;
 - double firstNum, secondNum;
 - firstNum = Convert.ToDouble(first);
 - secondNum = Convert.ToDouble(second);
 - //tambah
 - if(function == '+')
 - {
 - result = firstNum + secondNum;
 - layar.Text = result.ToString();
 - }
 - //kurang
 - else if(function == '-')
 - {
 - result = firstNum - secondNum;
 - layar.Text = result.ToString();
 - }
 - //bagi
 - else if(function == '/')
 - {
 - if(secondNum == '0')
 - {
 - layar.Text = "wrong";
 - }
 - else
 - {
 - result = firstNum / secondNum;
 - layar.Text = result.ToString();
 - }
 - }
 - //kali
 - else if(function == '*')
 - {
 - result = firstNum * secondNum;
 - layar.Text = result.ToString();
 - }
 - }
 - private void tombolkoma_Click(object sender, EventArgs e)
 - {
 - layar.Text += ".";
 - }
 - private void tombolnol_Click(object sender, EventArgs e)
 - {
 - layar.Text = "";
 - userInput += "0";
 - layar.Text += userInput;
 - }
 - }
 - }
 
Untuk hasil bentuk kalkulator dibawah ini :
Referensi untuk pembuatan tugas ini :
Terima kasih. Tetap semangat, tetap kuat, tetap hidup!!!
Komentar
Posting Komentar