#pragma once
namespace Modul92 {
using namespace
System;
using namespace
System::ComponentModel;
using namespace
System::Collections;
using namespace
System::Windows::Forms;
using namespace
System::Data;
using namespace
System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public
System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ txtbox1;
protected:
private: System::Windows::Forms::TextBox^ txt2;
private: System::Windows::Forms::TextBox^ txt3;
private: System::Windows::Forms::ComboBox^ cb1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ bthitung;
private: System::Windows::Forms::Label^ label2;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container
^components;
#pragma region
Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->txtbox1 = (gcnew
System::Windows::Forms::TextBox());
this->txt2 = (gcnew
System::Windows::Forms::TextBox());
this->txt3 = (gcnew
System::Windows::Forms::TextBox());
this->cb1 = (gcnew
System::Windows::Forms::ComboBox());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->bthitung = (gcnew
System::Windows::Forms::Button());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->SuspendLayout();
//
// txtbox1
//
this->txtbox1->Location =
System::Drawing::Point(12, 22);
this->txtbox1->Name = L"txtbox1";
this->txtbox1->Size =
System::Drawing::Size(100, 20);
this->txtbox1->TabIndex = 0;
//
// txt2
//
this->txt2->Location =
System::Drawing::Point(165, 23);
this->txt2->Name = L"txt2";
this->txt2->Size = System::Drawing::Size(100,
20);
this->txt2->TabIndex = 1;
//
// txt3
//
this->txt3->Location =
System::Drawing::Point(290, 23);
this->txt3->Name = L"txt3";
this->txt3->Size = System::Drawing::Size(100,
20);
this->txt3->TabIndex = 2;
//
// cb1
//
this->cb1->FormattingEnabled = true;
this->cb1->Items->AddRange(gcnew cli::array<
System::Object^ >(4) {L"+", L"-",
L"*", L"/"});
this->cb1->Location =
System::Drawing::Point(118, 22);
this->cb1->Name = L"cb1";
this->cb1->Size = System::Drawing::Size(41,
21);
this->cb1->TabIndex = 3;
//
// label1
//
this->label1->AutoSize
= true;
this->label1->Location =
System::Drawing::Point(271, 30);
this->label1->Name = L"label1";
this->label1->Size =
System::Drawing::Size(13, 13);
this->label1->TabIndex = 4;
this->label1->Text = L"=";
//
// bthitung
//
this->bthitung->Location =
System::Drawing::Point(301, 92);
this->bthitung->Name = L"bthitung";
this->bthitung->Size =
System::Drawing::Size(75, 23);
this->bthitung->TabIndex = 5;
this->bthitung->Text = L"Hitung";
this->bthitung->UseVisualStyleBackColor = true;
this->bthitung->Click += gcnew System::EventHandler(this,
&Form1::bthitung_Click);
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location =
System::Drawing::Point(12, 92);
this->label2->Name = L"label2";
this->label2->Size =
System::Drawing::Size(118, 26);
this->label2->TabIndex = 6;
this->label2->Text = L"Nama : Royan Rodiana\r\nNIM
: 49013031";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6,
13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(402,
143);
this->Controls->Add(this->label2);
this->Controls->Add(this->bthitung);
this->Controls->Add(this->label1);
this->Controls->Add(this->cb1);
this->Controls->Add(this->txt3);
this->Controls->Add(this->txt2);
this->Controls->Add(this->txtbox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew
System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void
bthitung_Click(System::Object^ sender,
System::EventArgs^ e) {
int
NilaiA,NilaiB;//variable bertype data int
double
hasil;//type data double
String^ operatornya;//variable
string
NilaiA = int::Parse(txtbox1->Text);
//nilai A diambil
dari textbox 1
NilaiB = int::Parse(txt2->Text);
//nilai b diambil
dari textbox 2
operatornya = cb1->Text;
//diambil dari
combobox
if
(operatornya=="+")
hasil = Convert::ToDouble(NilaiA + NilaiB);
//hasil di
konversi dari int ke double
else if(operatornya=="-")
hasil = Convert::ToDouble(NilaiA - NilaiB);
//hasil dikonversi
dari int ke double
else if (operatornya=="*")
hasil = Convert::ToDouble(NilaiA * NilaiB);
//hasil dikonversi
dari int ke double
else if(operatornya=="/")
hasil =
Convert::ToDouble(NilaiA)/Convert::ToDouble(NilaiB);
txt3->Text = hasil.ToString();
//hasilnya akan
ditampilkan di textbox ke 3
}
};
}
|
0 komentar:
Posting Komentar