C++ Microsoft Visual Studio

MyForm1.h

#pragma once
namespace Project12 {
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 MyForm
/// </summary>
public ref class MyForm : public
System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here //
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ComboBox^  comboBox1;
protected: private: System::Windows::Forms::TextBox^  textBox1;
private: System::Windows::Forms::Button^  button1;
private: System::Windows::Forms::TextBox^  textBox2;

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->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
// 
// comboBox1
// 
this->comboBox1->FormattingEnabled = true;
this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(2) { L”Fibonacci”, L”Ganjil Genap” });
this->comboBox1->Location = System::Drawing::Point(14, 15);
this->comboBox1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4);
this->comboBox1->Name = L”comboBox1″;
this->comboBox1->Size = System::Drawing::Size(175, 28);
this->comboBox1->TabIndex = 0;
this->comboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &MyForm::comboBox1_SelectedIndexChanged);
// 
// textBox1
// 
this->textBox1->Location = System::Drawing::Point(266, 18);
this->textBox1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4);
this->textBox1->Name = L”textBox1″; this->textBox1->Size = System::Drawing::Size(201, 26);
this->textBox1->TabIndex = 1;
// 
// button1
// 
this->button1->Location = System::Drawing::Point(24, 70);
this->button1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4);
this->button1->Name = L”button1″;
this->button1->Size = System::Drawing::Size(443, 41);
this->button1->TabIndex = 2;
this->button1->Text = L”jawab”;
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); // 
// textBox2
// 
this->textBox2->Location = System::Drawing::Point(34, 154);
this->textBox2->Margin = System::Windows::Forms::Padding(3, 4, 3, 4);
this->textBox2->Multiline = true;
this->textBox2->Name = L”textBox2″;
this->textBox2->Size = System::Drawing::Size(494, 215);
this->textBox2->TabIndex = 3;
// 
// MyForm
// 
this->AutoScaleDimensions = System::Drawing::SizeF(9, 20);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(542, 385);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->comboBox1);
this->Margin = System::Windows::Forms::Padding(3, 4, 3, 4);
this->Name = L”MyForm”;
this->Text = L”Dhimasel”;
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e)
{
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
textBox2->Text = “”; if (comboBox1->Text == “Ganjil Genap”)
{
int batas, hasil; batas = System::Convert::ToInt32(textBox1->Text);
for (Int32 i = 0; i <= batas; i++) { if (i % 2 == 0)
{
textBox2->Text += System::Convert::ToString(i) + ” Genap \r\n”;
}
else { textBox2->Text += System::Convert::ToString(i) + ” Ganjil \r\n”;
}
}
}
else { int n, t1 = 0, t2 = 1, nextTerm = 0; n = System::Convert::ToInt32(textBox1->Text); for (int i = 1; i <= n; ++i)
{
// Prints the first two terms. if (i == 1)
{
textBox2->Text += ” ” + System::Convert::ToString(t1);
}
if (i == 2)
{
textBox2->Text += System::Convert::ToString(t2) + ” “;
}
nextTerm = t1 + t2; t1 = t2; t2 = nextTerm;
textBox2->Text += System::Convert::ToString(nextTerm) + ” “;
}

}
}
};
}

MyForm.cpp

#include “MyForm1.h”
using namespace
Project12;
int main()
{
Application::Run(gcnew MyForm());
return 0;
}

Tinggalkan komentar