Anda di halaman 1dari 8

Modul Praktik

Visual Studio C++ 2010

disusun oleh :
Team Komputasi DTM SV UGM

PROGRAM DIPLOMA TEKNIK MESIN


DEPARTEMEN TEKNIK MESIN
SEKOLAH VOKASI UGM
2014

1 | Modul Visual Studio C++ 2010 DTM SV UGM


1. Project Baru

Pilih New Project

2 | Modul Visual Studio C++ 2010 DTM SV UGM


2. Menggunakan Label,textBox,Button

private: System::Void button1_Click(System::Object^ sender,


System::EventArgs^ e) {
double a,b,c;

a=Convert::ToDouble(textBox1->Text);
b=Convert::ToDouble(textBox2->Text);

c=a+b;

label5->Text = Convert::ToString(c);
textBox3->Text = Convert::ToString(c);
}

3 | Modul Visual Studio C++ 2010 DTM SV UGM


3. Menggunakan ComboBox,ListBox,GroupBox,RadioButton,CeckBox

comboBox
if (comboBox1->SelectedIndex == 0) c=a+b;
if (comboBox1->SelectedIndex == 1) c=a-b;

listBox
if (listBox1->SelectedIndex == 0) c=a+b;
if (listBox1->SelectedIndex == 1) c=a-b;

radioButton
if (radioButton1->Checked) c=a+b;
if (radioButton2->Checked) c=a-b;

checkBox
if (checkBox1->Checked)
if (checkBox1->Checked)

Reset Program
textBox1->Text="";
label5->Text="";

comboBox1->SelectedIndex=-1;
listBox1->SelectedIndex=-1;
radioButton1->Checked=false;

4 | Modul Visual Studio C++ 2010 DTM SV UGM


4. Menggunakan MassageBox

private: virtual System::Void button1_Click(System::Object^ sender,


system::EventArgs^ e){

double a,b,c;

a=Convert::ToDouble(textBox1->Text);

if (a>0)
label4->Text = "Positif";
if (a<0)
label4->Text = "Negatif";

if (a==0)
MessageBox::Show("Input tdk boleh nol !!");
}

5 | Modul Visual Studio C++ 2010 DTM SV UGM


5. Fungsi Input Juga Sebagai Output

private: System::Void button1_Click(System::Object^ sender,


System::EventArgs^ e)
{
float rp,dl;

if(textBox1->Text=="" && textBox2->Text=="")


MessageBox::Show("Input Tidak Boleh Kosong !!!");

if(textBox1->Text!="" && textBox2->Text!="")


MessageBox::Show("Input Tidak Boleh Dua !!!");

if(textBox1->Text!="" && textBox2->Text=="")


{
rp=Convert::ToDouble(textBox1->Text);
dl=rp/10000;
textBox2->Text = Convert::ToString(dl);
}

if(textBox1->Text=="" && textBox2->Text!="")


{
dl=Convert::ToDouble(textBox2->Text);
rp=dl*10000;
textBox1->Text = Convert::ToString(rp);
}

}
6 | Modul Visual Studio C++ 2010 DTM SV UGM
6. Menggunakan GridView

private: System::Void button1_Click(System::Object^ sender,


System::EventArgs^ e) {
int i,n,
double naw,nak,stp;

naw=Convert::ToDouble(textBox1->Text);
nak=Convert::ToDouble(textBox2->Text);
nak=Convert::ToDouble(textBox3->Text);

n=(nak-naw)/stp;

dataGridView1->RowCount=n+1;

for(i=1;i<=n;i++)
{
no=i+1
x=naw+(i*stp);
dx=2*x;
tgx=3*x;

dataGridView1->Rows[i]->Cells[0]->Value=no;
dataGridView1->Rows[i]->Cells[1]->Value=x;
dataGridView1->Rows[i]->Cells[2]->Value=dx;
dataGridView1->Rows[i]->Cells[3]->Value=tgx;
}

7 | Modul Visual Studio C++ 2010 DTM SV UGM


Reset GridView

dataGridView1->RowCount=1;

dataGridView1->Rows[0]->Cells[0]->Value="";
dataGridView1->Rows[0]->Cells[1]->Value="";
dataGridView1->Rows[0]->Cells[2]->Value="";
dataGridView1->Rows[0]->Cells[3]->Value="";
dataGridView1->Rows[0]->Cells[4]->Value="";

8 | Modul Visual Studio C++ 2010 DTM SV UGM

Anda mungkin juga menyukai