Program C++ (Windows Form Application) – Kalkulator Sederhana

Video Modul 9

Source Code:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    float nilaiA, nilaiB; //deklarasi variabel bertipe float

    double hasil; //deklarasi variabel bertipe double

    String^ operatornya; //deklarasi variabel bertipe string

    nilaiA = float::Parse(textBox1->Text); //mengubah nilai A menjadi teks

    nilaiB = float::Parse(textBox2->Text); //mengubah nilai B menjadi teks

        operatornya = comboBox1->Text; //inisialisasi operatornya mengambil teks dari comboBox1

    if (operatornya == “+”){ //jika operatornya = tambah

        hasil = Convert::ToDouble(nilaiA+nilaiB);} //maka hasil = nilai A + nilai B yang dikonversi ke tipe data double

    else
if (operatornya == “-“){ //jika operatornya = kurang

        hasil = Convert::ToDouble(nilaiA-nilaiB);} //hasil = nilai A – nilai B yang dikonversi ke tipe data double

    else
if (operatornya == “*”){ //jika operatornya = kali

        hasil = Convert::ToDouble(nilaiA*nilaiB);} //hasil = nilai A * nilai B yang dikonversi ke tipe data double

    else
if (operatornya == “/”){ //jika operatornya = bagi

        hasil = Convert::ToDouble(nilaiA/nilaiB);} //hasil = nilai A / nilai B yang dikonversi ke tipe data double

        textBox3->Text = hasil.ToString(); //menampilkan hasil yang dikonversi ke tipe data String pada textBox3

             }

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {

    this->Close(); //fungsi keluar dari program

         }

Hasil program:

 

Video tutorialnya:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s