Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello! I need some help completing this! Its a timesheet code, but For some reason I am struggling to get it all done. reference: https://www.youtube.com/watch?v=EMSV6ldBJSI&ab_channel=GutierrezProgramming

Hello! I need some help completing this! Its a timesheet code, but For some reason I am struggling to get it all done.

reference: https://www.youtube.com/watch?v=EMSV6ldBJSI&ab_channel=GutierrezProgramming

prompt:

Crete a windows form application for the time card. Crete several text boxes for the name of the employee and boxes for the time in and out: for two days of the week: morning in, lunch out, lunch in, evening out.

Crete text box for the total hours for the week, wage and total salary.

Catch all possible exceptions.

here's what I have so far (this is cppWindowFormsApp):

#pragma once#include namespace $safeprojectname$ { 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 MyForm ///  public ref class MyForm : public System::Windows::Forms::Form { public: MyForm(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: ///  /// Clean up any resources being used. ///  ~MyForm() { if (components) { delete components; } } private: System::Windows::Forms::Label^ mainTitle; private: System::Windows::Forms::Label^ clockInLabel; private: System::Windows::Forms::Label^ lunchOutLabel; private: System::Windows::Forms::Label^ lunchInLabel; private: System::Windows::Forms::Label^ eveningOutLabel; private: System::Windows::Forms::TextBox^ morningTextBox; private: System::Windows::Forms::TextBox^ lunchOutTextBox; private: System::Windows::Forms::TextBox^ lunchInTextBox; private: System::Windows::Forms::TextBox^ eveningTextBox; private: System::Windows::Forms::Button^ punchButton; private: System::Windows::Forms::Label^ hoursLabel; private: System::Windows::Forms::TextBox^ hoursTextBox; private: System::Windows::Forms::Label^ wageLabel; private: System::Windows::Forms::TextBox^ wageTextBox; private: System::Windows::Forms::Label^ salaryMadeLabel; private: System::Windows::Forms::Label^ moneyLabel; private: System::Windows::Forms::Label^ employeeLabel; private: System::Windows::Forms::TextBox^ employeeTextBox; private: System::Windows::Forms::Label^ day1Label; private: System::Windows::Forms::Label^ day2Label; private: System::Windows::Forms::TextBox^ textBox1; private: System::Windows::Forms::TextBox^ textBox2; private: System::Windows::Forms::Label^ label1; private: System::ComponentModel::IContainer^ components; protected: private: ///  /// Required designer variable. /// #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->mainTitle = (gcnew System::Windows::Forms::Label()); this->clockInLabel = (gcnew System::Windows::Forms::Label()); this->lunchOutLabel = (gcnew System::Windows::Forms::Label()); this->lunchInLabel = (gcnew System::Windows::Forms::Label()); this->eveningOutLabel = (gcnew System::Windows::Forms::Label()); this->morningTextBox = (gcnew System::Windows::Forms::TextBox()); this->lunchOutTextBox = (gcnew System::Windows::Forms::TextBox()); this->lunchInTextBox = (gcnew System::Windows::Forms::TextBox()); this->eveningTextBox = (gcnew System::Windows::Forms::TextBox()); this->punchButton = (gcnew System::Windows::Forms::Button()); this->hoursLabel = (gcnew System::Windows::Forms::Label()); this->hoursTextBox = (gcnew System::Windows::Forms::TextBox()); this->wageLabel = (gcnew System::Windows::Forms::Label()); this->wageTextBox = (gcnew System::Windows::Forms::TextBox()); this->salaryMadeLabel = (gcnew System::Windows::Forms::Label()); this->moneyLabel = (gcnew System::Windows::Forms::Label()); this->employeeLabel = (gcnew System::Windows::Forms::Label()); this->employeeTextBox = (gcnew System::Windows::Forms::TextBox()); this->day1Label = (gcnew System::Windows::Forms::Label()); this->day2Label = (gcnew System::Windows::Forms::Label()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->label1 = (gcnew System::Windows::Forms::Label()); this->SuspendLayout(); // // mainTitle // this->mainTitle->AutoSize = true; this->mainTitle->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 36, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->mainTitle->Location = System::Drawing::Point(336, 22); this->mainTitle->Name = L"mainTitle"; this->mainTitle->Size = System::Drawing::Size(265, 55); this->mainTitle->TabIndex = 0; this->mainTitle->Text = L"TimeSheet"; // // clockInLabel // this->clockInLabel->AutoSize = true; this->clockInLabel->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->clockInLabel->Location = System::Drawing::Point(15, 181); this->clockInLabel->Name = L"clockInLabel"; this->clockInLabel->Size = System::Drawing::Size(119, 25); this->clockInLabel->TabIndex = 1; this->clockInLabel->Text = L"Morning In:"; // // lunchOutLabel // this->lunchOutLabel->AutoSize = true; this->lunchOutLabel->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->lunchOutLabel->Location = System::Drawing::Point(15, 229); this->lunchOutLabel->Name = L"lunchOutLabel"; this->lunchOutLabel->Size = System::Drawing::Size(117, 25); this->lunchOutLabel->TabIndex = 2; this->lunchOutLabel->Text = L"Lunch Out:"; // // lunchInLabel // this->lunchInLabel->AutoSize = true; this->lunchInLabel->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->lunchInLabel->Location = System::Drawing::Point(15, 275); this->lunchInLabel->Name = L"lunchInLabel"; this->lunchInLabel->Size = System::Drawing::Size(100, 25); this->lunchInLabel->TabIndex = 3; this->lunchInLabel->Text = L"Lunch In:"; // // eveningOutLabel // this->eveningOutLabel->AutoSize = true; this->eveningOutLabel->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->eveningOutLabel->Location = System::Drawing::Point(15, 324); this->eveningOutLabel->Name = L"eveningOutLabel"; this->eveningOutLabel->Size = System::Drawing::Size(136, 25); this->eveningOutLabel->TabIndex = 4; this->eveningOutLabel->Text = L"Evening Out:"; // // morningTextBox // this->morningTextBox->Location = System::Drawing::Point(176, 187); this->morningTextBox->Name = L"morningTextBox"; this->morningTextBox->Size = System::Drawing::Size(100, 20); this->morningTextBox->TabIndex = 5; this->morningTextBox->Text = L"1:00 PM"; // // lunchOutTextBox // this->lunchOutTextBox->Location = System::Drawing::Point(175, 235); this->lunchOutTextBox->Name = L"lunchOutTextBox"; this->lunchOutTextBox->Size = System::Drawing::Size(100, 20); this->lunchOutTextBox->TabIndex = 6; this->lunchOutTextBox->Text = L"1:30 pm"; // // lunchInTextBox // this->lunchInTextBox->Location = System::Drawing::Point(175, 280); this->lunchInTextBox->Name = L"lunchInTextBox"; this->lunchInTextBox->Size = System::Drawing::Size(100, 20); this->lunchInTextBox->TabIndex = 7; this->lunchInTextBox->Text = L"2:00 pm"; // // eveningTextBox // this->eveningTextBox->Location = System::Drawing::Point(175, 330); this->eveningTextBox->Name = L"eveningTextBox"; this->eveningTextBox->Size = System::Drawing::Size(100, 20); this->eveningTextBox->TabIndex = 8; this->eveningTextBox->Text = L"5:00 PM"; // // punchButton // this->punchButton->Location = System::Drawing::Point(39, 376); this->punchButton->Name = L"punchButton"; this->punchButton->Size = System::Drawing::Size(109, 39); this->punchButton->TabIndex = 9; this->punchButton->Text = L"Punch-In Time"; this->punchButton->UseVisualStyleBackColor = true; this->punchButton->Click += gcnew System::EventHandler(this, &MyForm::punchButton_Click); // // hoursLabel // this->hoursLabel->AutoSize = true; this->hoursLabel->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->hoursLabel->Location = System::Drawing::Point(411, 187); this->hoursLabel->Name = L"hoursLabel"; this->hoursLabel->Size = System::Drawing::Size(129, 25); this->hoursLabel->TabIndex = 10; this->hoursLabel->Text = L"Total Hours:"; // // hoursTextBox // this->hoursTextBox->Location = System::Drawing::Point(428, 229); this->hoursTextBox->Name = L"hoursTextBox"; this->hoursTextBox->ReadOnly = true; this->hoursTextBox->Size = System::Drawing::Size(100, 20); this->hoursTextBox->TabIndex = 11; // // wageLabel // this->wageLabel->AutoSize = true; this->wageLabel->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->wageLabel->Location = System::Drawing::Point(411, 265); this->wageLabel->Name = L"wageLabel"; this->wageLabel->Size = System::Drawing::Size(142, 25); this->wageLabel->TabIndex = 12; this->wageLabel->Text = L"Hourly Wage:"; // // wageTextBox // this->wageTextBox->Location = System::Drawing::Point(428, 306); this->wageTextBox->Name = L"wageTextBox"; this->wageTextBox->Size = System::Drawing::Size(100, 20); this->wageTextBox->TabIndex = 13; this->wageTextBox->Text = L"10.25"; // // salaryMadeLabel // this->salaryMadeLabel->AutoSize = true; this->salaryMadeLabel->Location = System::Drawing::Point(229, 389); this->salaryMadeLabel->Name = L"salaryMadeLabel"; this->salaryMadeLabel->Size = System::Drawing::Size(108, 13); this->salaryMadeLabel->TabIndex = 14; this->salaryMadeLabel->Text = L"Salary Occumulated: "; // // moneyLabel // this->moneyLabel->AutoSize = true; this->moneyLabel->Location = System::Drawing::Point(343, 389); this->moneyLabel->Name = L"moneyLabel"; this->moneyLabel->Size = System::Drawing::Size(37, 13); this->moneyLabel->TabIndex = 15; this->moneyLabel->Text = L"Result"; // // employeeLabel // this->employeeLabel->AutoSize = true; this->employeeLabel->Location = System::Drawing::Point(343, 95); this->employeeLabel->Name = L"employeeLabel"; this->employeeLabel->Size = System::Drawing::Size(75, 13); this->employeeLabel->TabIndex = 16; this->employeeLabel->Text = L"Employees ID:"; // // employeeTextBox // this->employeeTextBox->Location = System::Drawing::Point(442, 88); this->employeeTextBox->Name = L"employeeTextBox"; this->employeeTextBox->Size = System::Drawing::Size(100, 20); this->employeeTextBox->TabIndex = 17; this->employeeTextBox->Text = L"A02897008"; // // day1Label // this->day1Label->AutoSize = true; this->day1Label->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->day1Label->Location = System::Drawing::Point(643, 187); this->day1Label->Name = L"day1Label"; this->day1Label->Size = System::Drawing::Size(74, 25); this->day1Label->TabIndex = 18; this->day1Label->Text = L"Day 1:"; // // day2Label // this->day2Label->AutoSize = true; this->day2Label->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, static_cast<:byte>(0))); this->day2Label->Location = System::Drawing::Point(789, 187); this->day2Label->Name = L"day2Label"; this->day2Label->Size = System::Drawing::Size(74, 25); this->day2Label->TabIndex = 19; this->day2Label->Text = L"Day 2:"; // // textBox1 // this->textBox1->Location = System::Drawing::Point(631, 229); this->textBox1->Name = L"textBox1"; this->textBox1->ReadOnly = true; this->textBox1->Size = System::Drawing::Size(100, 20); this->textBox1->TabIndex = 20; // // textBox2 // this->textBox2->Location = System::Drawing::Point(773, 234); this->textBox2->Name = L"textBox2"; this->textBox2->ReadOnly = true; this->textBox2->Size = System::Drawing::Size(100, 20); this->textBox2->TabIndex = 21; // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(0, 0); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(35, 13); this->label1->TabIndex = 22; this->label1->Text = L"label1"; // // MyForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(929, 459); this->Controls->Add(this->label1); this->Controls->Add(this->textBox2); this->Controls->Add(this->textBox1); this->Controls->Add(this->day2Label); this->Controls->Add(this->day1Label); this->Controls->Add(this->employeeTextBox); this->Controls->Add(this->employeeLabel); this->Controls->Add(this->moneyLabel); this->Controls->Add(this->salaryMadeLabel); this->Controls->Add(this->wageTextBox); this->Controls->Add(this->wageLabel); this->Controls->Add(this->hoursTextBox); this->Controls->Add(this->hoursLabel); this->Controls->Add(this->punchButton); this->Controls->Add(this->eveningTextBox); this->Controls->Add(this->lunchInTextBox); this->Controls->Add(this->lunchOutTextBox); this->Controls->Add(this->morningTextBox); this->Controls->Add(this->eveningOutLabel); this->Controls->Add(this->lunchInLabel); this->Controls->Add(this->lunchOutLabel); this->Controls->Add(this->clockInLabel); this->Controls->Add(this->mainTitle); this->Name = L"MyForm"; this->Text = L"TimeSheet"; this->ResumeLayout(false); this->PerformLayout(); }#pragma endregion double totalMinutes; double totalHours;private: System::Void punchButton_Click(System::Object^ sender, System::EventArgs^ e) { try { DateTime startTime; // store startTime -> textbox DateTime endTime; // store endTime -> textbox DateTime lunchOut; // store lunchOut -> lunchTextBox DateTime lunchIn; // store lunchIn -> lunchInTextBox double hourlyWage = Convert::ToDouble(this->wageTextBox->Text); // getting the hourly wage double amount = 0; double adjHours = 0; String^ formatAmount; startTime = Convert::ToDateTime(this->morningTextBox->Text); // Morning In textbox lunchOut = Convert::ToDateTime(this->lunchOutTextBox->Text); // Lunch Out textbox lunchIn = Convert::ToDateTime(this->lunchInTextBox->Text); // Lunch In textbox endTime = Convert::ToDateTime(this->eveningTextBox->Text); // Evening Out Textbox TimeSpan timeBetweenStartAndEnd = endTime - startTime; // time elapsed from start to end TimeSpan timeBetweenLunchOutAndIn = lunchIn - lunchOut; // time elapsed from lunch out to lunch in // total hours totalHours = timeBetweenStartAndEnd.TotalHours; // total number of minutes totalMinutes = timeBetweenStartAndEnd.TotalMinutes; // if lunch isn't paid, subtract lunch duration from total hours if (timeBetweenLunchOutAndIn.TotalMinutes > 0) { totalHours -= timeBetweenLunchOutAndIn.TotalHours; } // adjust total hours with minutes adjHours = totalHours + (totalMinutes / 60); // amount amount = adjHours * hourlyWage; // convert to textbox showing result formatAmount = amount.ToString("C"); // format 'amount' as a currency this->moneyLabel->Text = formatAmount; // print adjusted total hours to hoursTextBox this->hoursTextBox->Text = Convert::ToString(adjHours + " hours"); } catch (DivideByZeroException^ myException) { MessageBox::Show("You cannot divide by zero"); } catch (FormatException^ myException) { MessageBox::Show("Invalid format, please fill in the required fields"); } catch (...) { MessageBox::Show("Please check if all fields are filled in properly."); }}};}
image text in transcribed \f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

=+how much revenue will the government get?

Answered: 1 week ago

Question

1 what does yellow colour on the map represent?

Answered: 1 week ago