Asslamualaikum sahabat,selamat happy hahah hari ini hari pertama selesai UTS semester 2 ini untuk tes pemogramannya sendiri kami membuat kalkulator sederhana , konversi bilangan ke biner,hexa,oktal dan desimal, + buat fitur tambahannya.nah berikut ini hasil kerja saya selama 4 sesi itu semoga bermanfaat dan selamat berkreasi
>open microsoft visual c# 2010
>caranya sama seperti biasa
> ini program kalkulator saya
Nah tampilannya seperti ini :)
>open microsoft visual c# 2010
>caranya sama seperti biasa
> ini program kalkulator saya
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
bool blcheck;
string strOperator;
string stfNumber;
decimal dcanswer;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs
e)
{
Button btnNumbers = (Button)sender;
if (blcheck == true)
{
textBox1.Text = " ";
}
textBox1.Text += btnNumbers.Text;
blcheck
= false;
}
private void
button12_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("."))
{
return;
}
textBox1.Text += button12.Text;
}
private void
button16_Click(object sender, EventArgs e)
{
Button btnOperators = (Button)sender;
strOperator = btnOperators.Text;
stfNumber = textBox1.Text;
blcheck = true;
}
private void
button17_Click(object sender, EventArgs e)
{
if (strOperator == ("+"))
{
dcanswer = Convert.ToDecimal(stfNumber)+Convert.ToDecimal(textBox1.Text);
textBox1.Text = Convert.ToString(dcanswer);
}
else if (strOperator
== ("/"))
{
dcanswer = Convert.ToDecimal(stfNumber)/
Convert.ToDecimal(textBox1.Text);
textBox1.Text = Convert.ToString(dcanswer);
}
else if (strOperator
== ("*"))
{
dcanswer = Convert.ToDecimal(stfNumber)*Convert.ToDecimal(textBox1.Text);
textBox1.Text = Convert.ToString(dcanswer);
}
else if (strOperator
== ("-"))
{
dcanswer = Convert.ToDecimal(stfNumber)
- Convert.ToDecimal(textBox1.Text);
textBox1.Text = Convert.ToString(dcanswer);
}
}
private void copyToolStripMenuItem_Click(object sender, EventArgs
e)
{
Clipboard.SetText(textBox1.Text);
}
private void
pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Text += Clipboard.GetText();
}
private void
Form1_KeyPress(object sender, KeyPressEventArgs e)
{
int i;
if (int.TryParse(e.KeyChar.ToString(),
out i))
{
if (blcheck == true)
{
textBox1.Text = " ";
}
textBox1.Text += e.KeyChar;
blcheck = false;
}
}
private void
button25_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length>0)
textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length-1);
}
private void
Form1_Load(object sender, EventArgs e)
{
this.KeyPreview = true;
}
private void
button26_Click(object sender, EventArgs e)
{
textBox1.Text = " ";
}
private void
button27_Click(object sender, EventArgs e)
{
textBox1.Text=" ";
textBox2.Text =" ";
textBox3.Text = " ";
textBox4.Text = " ";
textBox5.Text = " ";
textBox6.Text = " ";
stfNumber = " ";
}
private void
button11_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("-"))
textBox1.Text = textBox1.Text.Remove(0, 1);
else
textBox1.Text = "-" +
textBox1.Text;
}
private void
button20_Click(object sender, EventArgs e)
{
double root =Math.Sqrt
(Convert.ToDouble (textBox1.Text));
textBox1.Text = Convert.ToString(root);
}
private void
button21_Click(object sender, EventArgs e)
{
textBox2.Text
= Int16.Parse(textBox1.Text).ToString("x");
textBox3.Text = (int.Parse(textBox2.Text,
System.Globalization.NumberStyles.HexNumber)).ToString();
textBox4.Text = (int.Parse(textBox1.Text,
System.Globalization.NumberStyles.AllowDecimalPoint)).ToString();
textBox5.Text = DecimalToBinary(textBox1.Text);
textBox6.Text = DecimalToOctal(textBox1.Text);
}
public string
DecimalToBinary(string data)
{
string result = string.Empty;
int rem = 0;
try
{
int num = int.Parse(data);
while (num > 0)
{
rem = num % 2;
num = num / 2;
result = rem.ToString() + result;
}
}
catch (Exception
ex)
{
MessageBox.Show(ex.Message);
}
return result;
}
public string
DecimalToOctal(string data)
{
string result = string.Empty;
int rem = 0;
try
{
int num = int.Parse(data);
while (num > 0)
{
rem = num % 8;
num = num / 8;
result = rem.ToString() + result;
}
}
catch (Exception
ex)
{
MessageBox.Show(ex.Message);
}
return result;
}
}
}
Comments
Post a Comment