Milestone One: Introduction to Forms C++ For Milestone One you will build/design
ID: 666889 • Letter: M
Question
Milestone One: Introduction to Forms C++
For Milestone One you will build/design the basic infrastructure of the C++ graphical user interface. The following operations/features must be provided at a minimum:
Provide widgets for specifying a departure city, destination city, number of travelers, cabin grade (first class, business, coach, etc.), and number of checked bags. The GUI should provide a total cost once all the selections are made.
There should be one main “form” that will contain the entire GUI.
There should be one pushbutton for gracefully exiting the application.
Use pull-down widgets (selection lists or combo boxes) to allow the user to select the cities and cabin grade.
Provide text widgets for specifying the number of travelers and number of checked bags.
Code in C++
Explanation / Answer
Visual C++ is being used to implement the desired functionality.
From Visual Studio, A empty project is being added.And then , A form (MyForm.h) is being added into that.
So, the code for the MyForm.h is given below.
------------Form.h-------------------------------
#pragma once
namespace FormApp {
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::GroupBox^ groupBox1;
protected:
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::ComboBox^ comboBoxCabinGrade;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::ComboBox^ comboBoxDestinationCities;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::ComboBox^ comboBoxDepartureCities;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ buttonExit;
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->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->comboBoxDepartureCities = (gcnew System::Windows::Forms::ComboBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->comboBoxDestinationCities = (gcnew System::Windows::Forms::ComboBox());
this->label3 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label4 = (gcnew System::Windows::Forms::Label());
this->comboBoxCabinGrade = (gcnew System::Windows::Forms::ComboBox());
this->label5 = (gcnew System::Windows::Forms::Label());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->buttonExit = (gcnew System::Windows::Forms::Button());
this->groupBox1->SuspendLayout();
this->SuspendLayout();
//
// groupBox1
//
this->groupBox1->Controls->Add(this->textBox2);
this->groupBox1->Controls->Add(this->label5);
this->groupBox1->Controls->Add(this->comboBoxCabinGrade);
this->groupBox1->Controls->Add(this->label4);
this->groupBox1->Controls->Add(this->textBox1);
this->groupBox1->Controls->Add(this->label3);
this->groupBox1->Controls->Add(this->comboBoxDestinationCities);
this->groupBox1->Controls->Add(this->label2);
this->groupBox1->Controls->Add(this->comboBoxDepartureCities);
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Location = System::Drawing::Point(12, 12);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(626, 362);
this->groupBox1->TabIndex = 0;
this->groupBox1->TabStop = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(107, 45);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(74, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Departure City";
//
// comboBoxDepartureCities
//
this->comboBoxDepartureCities->FormattingEnabled = true;
this->comboBoxDepartureCities->Location = System::Drawing::Point(187, 37);
this->comboBoxDepartureCities->Name = L"comboBoxDepartureCities";
this->comboBoxDepartureCities->Size = System::Drawing::Size(121, 21);
this->comboBoxDepartureCities->TabIndex = 1;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(101, 79);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(80, 13);
this->label2->TabIndex = 2;
this->label2->Text = L"Destination City";
//
// comboBoxDestinationCities
//
this->comboBoxDestinationCities->FormattingEnabled = true;
this->comboBoxDestinationCities->Location = System::Drawing::Point(187, 71);
this->comboBoxDestinationCities->Name = L"comboBoxDestinationCities";
this->comboBoxDestinationCities->Size = System::Drawing::Size(121, 21);
this->comboBoxDestinationCities->TabIndex = 3;
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(83, 115);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(98, 13);
this->label3->TabIndex = 4;
this->label3->Text = L"Number of Traveler";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(187, 112);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(121, 20);
this->textBox1->TabIndex = 5;
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(115, 169);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(66, 13);
this->label4->TabIndex = 6;
this->label4->Text = L"Cabin Grade";
//
// comboBoxCabinGrade
//
this->comboBoxCabinGrade->FormattingEnabled = true;
this->comboBoxCabinGrade->Items->AddRange(gcnew cli::array< System::Object^ >(3) { L"First Class", L"Business", L"Coach" });
this->comboBoxCabinGrade->Location = System::Drawing::Point(187, 161);
this->comboBoxCabinGrade->Name = L"comboBoxCabinGrade";
this->comboBoxCabinGrade->Size = System::Drawing::Size(121, 21);
this->comboBoxCabinGrade->TabIndex = 7;
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(52, 207);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(129, 13);
this->label5->TabIndex = 8;
this->label5->Text = L"Number of Checked Bags";
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(187, 200);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(100, 20);
this->textBox2->TabIndex = 9;
//
// buttonExit
//
this->buttonExit->Location = System::Drawing::Point(447, 395);
this->buttonExit->Name = L"buttonExit";
this->buttonExit->Size = System::Drawing::Size(75, 23);
this->buttonExit->TabIndex = 1;
this->buttonExit->Text = L"Exit";
this->buttonExit->UseVisualStyleBackColor = true;
this->buttonExit->Click += gcnew System::EventHandler(this, &MyForm::buttonExit_Click);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(650, 428);
this->Controls->Add(this->buttonExit);
this->Controls->Add(this->groupBox1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
};
}
-------------MyForm.cpp---------------
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
System::Void FormApp::buttonExit_Click(System::Object^ sender, System::EventArgs^ e) {
System::Application::Exit();
}
If run using F5,
then A form will be shown with the desired functionality.