I am relatively new to the C++ world - I am working on a form control that is supposed to use a List box to pull a value out of an array of values and display it in a text box.
This is way above my head, but I want to figure it out.
Here is my task:
1-Write a program for Eddies Equipment Rental
2-Build a windows form that looks like this:

3-Eddie Charges one amount for full day rentals and another amout for half days.
4-Use 3 parallel arrays to store the data
Data is as follows:

5-Load the list box during the form load (optional)
6-The user should click on the item in the list box to select the equipment GOT THIS
7-the user must enter an f or h for full or half day GOT THIS
8-the Display Charge button will display the approrpiate amount in the rental charge text box I really need help with this.
the Clear button will clear the 2 text boxes GOT THIS
I have the form built - and the clear button working.
I have the listbox issueing values based on selection - but don't know how to put that data in to an array that is also getting data from the Duration Text box. I actually am not sure how to get the data outside the function itself. To use it with the click function of the Dsiplay Button.
I got the txtDuration to validate input - and it uses a message box to alert the user if they input the wrong thing. Though the built in error handler is a bit annoyoing - if you hit the backspace the program throws another error message box - that I didn't program, would like to turn that off. it tells you that you must have exactly one character - which is not necresary.
Alot of the problem I am having is that I don't know where to put stuff - when there is already a ton of code generated that I don't understand.
Any help would be greatly appreciated.
code for form that I have already is below:
This is way above my head, but I want to figure it out.
Here is my task:
1-Write a program for Eddies Equipment Rental
2-Build a windows form that looks like this:

3-Eddie Charges one amount for full day rentals and another amout for half days.
4-Use 3 parallel arrays to store the data
Data is as follows:

5-Load the list box during the form load (optional)
6-The user should click on the item in the list box to select the equipment GOT THIS
7-the user must enter an f or h for full or half day GOT THIS
8-the Display Charge button will display the approrpiate amount in the rental charge text box I really need help with this.
the Clear button will clear the 2 text boxes GOT THIS
I have the form built - and the clear button working.
I have the listbox issueing values based on selection - but don't know how to put that data in to an array that is also getting data from the Duration Text box. I actually am not sure how to get the data outside the function itself. To use it with the click function of the Dsiplay Button.
I got the txtDuration to validate input - and it uses a message box to alert the user if they input the wrong thing. Though the built in error handler is a bit annoyoing - if you hit the backspace the program throws another error message box - that I didn't program, would like to turn that off. it tells you that you must have exactly one character - which is not necresary.
Alot of the problem I am having is that I don't know where to put stuff - when there is already a ton of code generated that I don't understand.
Any help would be greatly appreciated.
code for form that I have already is below:
Code:
#pragma once
namespace Final {
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::ListBox^ lstEquipment;
protected:
private: System::Windows::Forms::Label^ lblDuration;
private: System::Windows::Forms::TextBox^ txtDuration;
private: System::Windows::Forms::Label^ lblCharge;
private: System::Windows::Forms::TextBox^ txtCharge;
private: System::Windows::Forms::Button^ btnDisplay;
private: System::Windows::Forms::Button^ btnClear;
private: System::Windows::Forms::Label^ lblInstruction;
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->lstEquipment = (gcnew System::Windows::Forms::ListBox());
this->lblDuration = (gcnew System::Windows::Forms::Label());
this->txtDuration = (gcnew System::Windows::Forms::TextBox());
this->lblCharge = (gcnew System::Windows::Forms::Label());
this->txtCharge = (gcnew System::Windows::Forms::TextBox());
this->btnDisplay = (gcnew System::Windows::Forms::Button());
this->btnClear = (gcnew System::Windows::Forms::Button());
this->lblInstruction = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// lstEquipment
//
this->lstEquipment->FormattingEnabled = true;
this->lstEquipment->Items->AddRange(gcnew cli::array< System::Object^ >(3) {L"1- Rug Cleaner", L"2- Lawn Mower", L"3- Paint Sprayer"});
this->lstEquipment->Location = System::Drawing::Point(95, 46);
this->lstEquipment->Name = L"lstEquipment";
this->lstEquipment->Size = System::Drawing::Size(158, 56);
this->lstEquipment->TabIndex = 1;
this->lstEquipment->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::Item_Selected);
//
// lblDuration
//
this->lblDuration->AutoSize = true;
this->lblDuration->Location = System::Drawing::Point(92, 154);
this->lblDuration->Name = L"lblDuration";
this->lblDuration->Size = System::Drawing::Size(130, 13);
this->lblDuration->TabIndex = 2;
this->lblDuration->Text = L"Select a Duration (F or H):";
//
// txtDuration
//
this->txtDuration->Location = System::Drawing::Point(228, 150);
this->txtDuration->Name = L"txtDuration";
this->txtDuration->Size = System::Drawing::Size(34, 20);
this->txtDuration->TabIndex = 3;
this->txtDuration->TextChanged += gcnew System::EventHandler(this, &Form1::Input_Duration);
//
// lblCharge
//
this->lblCharge->AutoSize = true;
this->lblCharge->Location = System::Drawing::Point(92, 179);
this->lblCharge->Name = L"lblCharge";
this->lblCharge->Size = System::Drawing::Size(78, 13);
this->lblCharge->TabIndex = 4;
this->lblCharge->Text = L"Rental Charge:";
//
// txtCharge
//
this->txtCharge->Location = System::Drawing::Point(176, 176);
this->txtCharge->Name = L"txtCharge";
this->txtCharge->Size = System::Drawing::Size(86, 20);
this->txtCharge->TabIndex = 5;
//
// btnDisplay
//
this->btnDisplay->Location = System::Drawing::Point(74, 217);
this->btnDisplay->Name = L"btnDisplay";
this->btnDisplay->Size = System::Drawing::Size(75, 23);
this->btnDisplay->TabIndex = 6;
this->btnDisplay->Text = L"Display Charge";
this->btnDisplay->UseVisualStyleBackColor = true;
this->btnDisplay->Click += gcnew System::EventHandler(this, &Form1::Display_Charge);
//
// btnClear
//
this->btnClear->Location = System::Drawing::Point(221, 217);
this->btnClear->Name = L"btnClear";
this->btnClear->Size = System::Drawing::Size(75, 23);
this->btnClear->TabIndex = 7;
this->btnClear->Text = L"Clear";
this->btnClear->UseVisualStyleBackColor = true;
this->btnClear->Click += gcnew System::EventHandler(this, &Form1::ClearInput);
//
// lblInstruction
//
this->lblInstruction->AutoSize = true;
this->lblInstruction->Location = System::Drawing::Point(105, 30);
this->lblInstruction->Name = L"lblInstruction";
this->lblInstruction->Size = System::Drawing::Size(124, 13);
this->lblInstruction->TabIndex = 8;
this->lblInstruction->Text = L"Click on the Item to Rent";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(359, 264);
this->Controls->Add(this->lblInstruction);
this->Controls->Add(this->btnClear);
this->Controls->Add(this->btnDisplay);
this->Controls->Add(this->txtCharge);
this->Controls->Add(this->lblCharge);
this->Controls->Add(this->txtDuration);
this->Controls->Add(this->lblDuration);
this->Controls->Add(this->lstEquipment);
this->Name = L"Form1";
this->Text = L"Eddies Equipment Rental";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void ClearInput(System::Object^ sender, System::EventArgs^ e)
{
txtDuration->Clear();
txtCharge->Clear();
}
private: System::Void Item_Selected(System::Object^ sender, System::EventArgs^ e)
{
int Item;
if(lstEquipment->SelectedIndex==0)
Item=1;
else if(lstEquipment->SelectedIndex==1)
Item=2;
else
Item=3;
}
private: System::Void Input_Duration(System::Object^ sender, System::EventArgs^ e)
{
int Duration;
wchar_t convertDuration;
convertDuration = System::Convert::ToChar(txtDuration->Text);
if(txtDuration->Text=="F" || txtDuration->Text=="f")
Duration=1;
else if(txtDuration->Text=="H" || txtDuration->Text=="h")
Duration=2;
else
MessageBox::Show("Your Entry Must be 'F' for Full Day or 'H' for Half Day","Input Error", MessageBoxButtons::OKCancel,MessageBoxIcon::Asterisk);
}
private: System::Void Display_Charge(System::Object^ sender, System::EventArgs^ e)
{
}
};
}