Here is the code: form1.h
#pragma once
namespace CalculateTips {
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 for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
///
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Panel^ panel1;
private: System::Windows::Forms::RadioButton^ radioButton4;
private: System::Windows::Forms::RadioButton^ radioButton3;
private: System::Windows::Forms::RadioButton^ radioButton2;
private: System::Windows::Forms::RadioButton^ radioButton1;
private: System::Windows::Forms::TextBox^ txtOther;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TextBox^ txtMeal;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::TextBox^ txtTaxPercent;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ lblTotal;
protected:
private:
///
/// Required designer variable.
///
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->panel1 = (gcnew System::Windows::Forms::Panel());
this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton4 = (gcnew System::Windows::Forms::RadioButton());
this->txtOther = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->txtMeal = (gcnew System::Windows::Forms::TextBox());
this->label3 = (gcnew System::Windows::Forms::Label());
this->txtTaxPercent = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->lblTotal = (gcnew System::Windows::Forms::Label());
this->panel1->SuspendLayout();
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 24, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->label1->ForeColor = System::Drawing::Color::FromArgb(static_cast
static_cast
this->label1->Location = System::Drawing::Point(13, 13);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(191, 37);
this->label1->TabIndex = 0;
this->label1->Text = L"Tip Calcutor";
//
// panel1
//
this->panel1->Controls->Add(this->txtOther);
this->panel1->Controls->Add(this->radioButton4);
this->panel1->Controls->Add(this->radioButton3);
this->panel1->Controls->Add(this->radioButton2);
this->panel1->Controls->Add(this->radioButton1);
this->panel1->Location = System::Drawing::Point(20, 70);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(228, 151);
this->panel1->TabIndex = 1;
//
// radioButton1
//
this->radioButton1->AutoSize = true;
this->radioButton1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->radioButton1->Location = System::Drawing::Point(24, 21);
this->radioButton1->Name = L"radioButton1";
this->radioButton1->Size = System::Drawing::Size(118, 28);
this->radioButton1->TabIndex = 0;
this->radioButton1->TabStop = true;
this->radioButton1->Text = L"10 Percent";
this->radioButton1->UseVisualStyleBackColor = true;
//
// radioButton2
//
this->radioButton2->AutoSize = true;
this->radioButton2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->radioButton2->Location = System::Drawing::Point(24, 45);
this->radioButton2->Name = L"radioButton2";
this->radioButton2->Size = System::Drawing::Size(118, 28);
this->radioButton2->TabIndex = 1;
this->radioButton2->TabStop = true;
this->radioButton2->Text = L"15 Percent";
this->radioButton2->UseVisualStyleBackColor = true;
//
// radioButton3
//
this->radioButton3->AutoSize = true;
this->radioButton3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->radioButton3->Location = System::Drawing::Point(24, 68);
this->radioButton3->Name = L"radioButton3";
this->radioButton3->Size = System::Drawing::Size(118, 28);
this->radioButton3->TabIndex = 2;
this->radioButton3->TabStop = true;
this->radioButton3->Text = L"20 Percent";
this->radioButton3->UseVisualStyleBackColor = true;
//
// radioButton4
//
this->radioButton4->AutoSize = true;
this->radioButton4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->radioButton4->Location = System::Drawing::Point(24, 91);
this->radioButton4->Name = L"radioButton4";
this->radioButton4->Size = System::Drawing::Size(75, 28);
this->radioButton4->TabIndex = 3;
this->radioButton4->TabStop = true;
this->radioButton4->Text = L"Other";
this->radioButton4->UseVisualStyleBackColor = true;
//
// txtOther
//
this->txtOther->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->txtOther->Location = System::Drawing::Point(105, 98);
this->txtOther->Name = L"txtOther";
this->txtOther->Size = System::Drawing::Size(100, 29);
this->txtOther->TabIndex = 4;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->label2->Location = System::Drawing::Point(20, 248);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(172, 24);
this->label2->TabIndex = 2;
this->label2->Text = L"Enter Meal Amount";
//
// txtMeal
//
this->txtMeal->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->txtMeal->Location = System::Drawing::Point(198, 252);
this->txtMeal->Name = L"txtMeal";
this->txtMeal->Size = System::Drawing::Size(100, 29);
this->txtMeal->TabIndex = 3;
//
// label3
//
this->label3->AutoSize = true;
this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->label3->Location = System::Drawing::Point(20, 294);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(112, 24);
this->label3->TabIndex = 4;
this->label3->Text = L"Tax Percent";
//
// txtTaxPercent
//
this->txtTaxPercent->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->txtTaxPercent->Location = System::Drawing::Point(198, 294);
this->txtTaxPercent->Name = L"txtTaxPercent";
this->txtTaxPercent->Size = System::Drawing::Size(100, 29);
this->txtTaxPercent->TabIndex = 5;
//
// button1
//
this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->button1->Location = System::Drawing::Point(24, 352);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(108, 37);
this->button1->TabIndex = 6;
this->button1->Text = L"Calculate";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// lblTotal
//
this->lblTotal->AutoSize = true;
this->lblTotal->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
this->lblTotal->Location = System::Drawing::Point(194, 352);
this->lblTotal->Name = L"lblTotal";
this->lblTotal->Size = System::Drawing::Size(0, 24);
this->lblTotal->TabIndex = 7;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::Color::FromArgb(static_cast
static_cast
this->ClientSize = System::Drawing::Size(551, 462);
this->Controls->Add(this->lblTotal);
this->Controls->Add(this->button1);
this->Controls->Add(this->txtTaxPercent);
this->Controls->Add(this->label3);
this->Controls->Add(this->txtMeal);
this->Controls->Add(this->label2);
this->Controls->Add(this->panel1);
this->Controls->Add(this->label1);
this->Name = L"Form1";
this->Text = L"Form1";
this->panel1->ResumeLayout(false);
this->panel1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
double amount = double::Parse(txtMeal->Text);
double taxPercent=0;
if (double::Parse(txtTaxPercent->Text) > 1)
{
taxPercent=double::Parse(txtTaxPercent->Text)/100;
}
else
{
taxPercent=double::Parse(txtTaxPercent->Text);
}
double tipAmount=0;
double percent=0;
if (radioButton1->Checked)
{
percent=.1;
}
else if (radioButton2->Checked)
{
percent=.15;
}
else if (radioButton3->Checked)
{
percent =.2;
} //end of if
else
{
if (double::Parse(txtOther->Text)>1)
{
percent=double::Parse(txtOther->Text)/100;
}
else
{
percent=double::Parse(txtOther->Text);
} //end of embedded if
}//end of else
tipAmount=amount * percent;
double taxAmount=amount * taxPercent;
double total =amount + taxAmount + tipAmount;
lblTotal->Text="At " + percent.ToString() + " your tip will be "
+ tipAmount.ToString("$ #,##0.00") + "\n"
+ "Your tax is " + taxAmount.ToString("$ #,##0.00") + "\n"
+ "Your Total is " + total.ToString("$ #,##0.00");
}
};
}
No comments:
Post a Comment