"MyForm.h" By GGMethos (https://pastebin.com/u/GGMethos) URL: https://pastebin.com/ePLS8aav Created on: Friday 7th of March 2014 06:57:01 PM CDT Retrieved on: Monday 21 of December 2020 05:21:59 AM UTC #pragma once #include namespace Lab3 { 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^ label1; private: System::Windows::Forms::TextBox^ textBox1; private: System::Windows::Forms::Label^ label2; private: System::Windows::Forms::TextBox^ textBox2; private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::TextBox^ textBox3; private: System::Windows::Forms::Label^ label4; private: System::Windows::Forms::TextBox^ textBox4; private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::Button^ button2; private: System::Windows::Forms::Button^ button3; private: System::Windows::Forms::ErrorProvider^ errorProvider1; 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->components = (gcnew System::ComponentModel::Container()); this->label1 = (gcnew System::Windows::Forms::Label()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->label2 = (gcnew System::Windows::Forms::Label()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->label3 = (gcnew System::Windows::Forms::Label()); this->textBox3 = (gcnew System::Windows::Forms::TextBox()); this->label4 = (gcnew System::Windows::Forms::Label()); this->textBox4 = (gcnew System::Windows::Forms::TextBox()); this->button1 = (gcnew System::Windows::Forms::Button()); this->button2 = (gcnew System::Windows::Forms::Button()); this->button3 = (gcnew System::Windows::Forms::Button()); this->errorProvider1 = (gcnew System::Windows::Forms::ErrorProvider(this->components)); (cli::safe_cast(this->errorProvider1))->BeginInit(); this->SuspendLayout(); // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(47, 9); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(90, 13); this->label1->TabIndex = 0; this->label1->Text = L"Loan Amount (C)"; this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click); // // textBox1 // this->textBox1->Location = System::Drawing::Point(62, 37); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(51, 20); this->textBox1->TabIndex = 1; this->textBox1->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox1_TextChanged); // // label2 // this->label2->AutoSize = true; this->label2->Location = System::Drawing::Point(188, 9); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(148, 13); this->label2->TabIndex = 2; this->label2->Text = L"Interest Rate Percentage (R)"; this->label2->Click += gcnew System::EventHandler(this, &MyForm::label2_Click); // // textBox2 // this->textBox2->Location = System::Drawing::Point(222, 37); this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(67, 20); this->textBox2->TabIndex = 3; // // label3 // this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(379, 9); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(171, 13); this->label3->TabIndex = 4; this->label3->Text = L"Number of Monthly Payments (N)"; // // textBox3 // this->textBox3->Location = System::Drawing::Point(391, 37); this->textBox3->Name = L"textBox3"; this->textBox3->Size = System::Drawing::Size(140, 20); this->textBox3->TabIndex = 5; this->textBox3->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox3_TextChanged); // // label4 // this->label4->AutoSize = true; this->label4->Location = System::Drawing::Point(614, 9); this->label4->Name = L"label4"; this->label4->Size = System::Drawing::Size(110, 13); this->label4->TabIndex = 6; this->label4->Text = L"Monthly Payment (P)"; // // textBox4 // this->textBox4->Location = System::Drawing::Point(604, 37); this->textBox4->Name = L"textBox4"; this->textBox4->Size = System::Drawing::Size(141, 20); this->textBox4->TabIndex = 7; // // button1 // this->button1->Location = System::Drawing::Point(62, 82); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(51, 23); this->button1->TabIndex = 8; this->button1->Text = L"P="; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); // // button2 // this->button2->Location = System::Drawing::Point(222, 82); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(67, 23); this->button2->TabIndex = 9; this->button2->Text = L"R="; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click); // // button3 // this->button3->Location = System::Drawing::Point(391, 82); this->button3->Name = L"button3"; this->button3->Size = System::Drawing::Size(140, 23); this->button3->TabIndex = 10; this->button3->Text = L"N="; this->button3->UseVisualStyleBackColor = true; this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click); // // errorProvider1 // this->errorProvider1->ContainerControl = this; // // MyForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(758, 125); this->Controls->Add(this->button3); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->Controls->Add(this->textBox4); this->Controls->Add(this->label4); this->Controls->Add(this->textBox3); this->Controls->Add(this->label3); this->Controls->Add(this->textBox2); this->Controls->Add(this->label2); this->Controls->Add(this->textBox1); this->Controls->Add(this->label1); this->Name = L"MyForm"; this->Text = L"Loan Calculator"; (cli::safe_cast(this->errorProvider1))->EndInit(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) { } private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void textBox3_TextChanged(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { double loanAmount = System::Convert::ToDouble(textBox1->Text); double interestRate = System::Convert::ToDouble(textBox2->Text); double numberOfMonths = System::Convert::ToDouble(textBox3->Text); double rRate = interestRate / 1200; double numerater = ((loanAmount * rRate) * (pow((1 + rRate), numberOfMonths))); double denominater = ((pow((1 + rRate), numberOfMonths)) - 1); double newr = numerater / denominater; textBox4->Text = System::Convert::ToString(newr); } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { if (textBox2->Text == ""){ double loanAmount = System::Convert::ToDouble(textBox1->Text); double payment = System::Convert::ToDouble(textBox4->Text); double numberOfMonths = System::Convert::ToDouble(textBox3->Text); double initial = (2 * (numberOfMonths * payment - loanAmount) / (numberOfMonths * loanAmount)); double rOld = (initial * (pow((1 + initial), numberOfMonths)) / ((pow((1 + initial), numberOfMonths) - 1))) - (payment / loanAmount); double b1 = payment * pow((1. + rOld), -numberOfMonths); double c1 = (rOld * loanAmount); double num = payment - (b1 - c1); double denom = numberOfMonths * (payment * pow((1. + rOld), (-numberOfMonths - 1)) - loanAmount); int terminate = 0; double rNew; while (terminate == 0) { //terminating factor to exit the loop rNew = rOld - (num / denom); if (fabs(rNew - rOld) >= 0.01) //loops until difference is less than .01, then terminates { rOld = rNew; } else { terminate = 1; } textBox2->Text = System::Convert::ToString(rNew); //outputs desired results } } else{ errorProvider1->SetError(textBox2, "Please keep this blank to calculate the interest rate."); //error check } } /*private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { double loanAmount = System::Convert::ToDouble(textBox1->Text); //converts the input value to double, if it wasn't already input as such double annualInterestRate = System::Convert::ToDouble(textBox2->Text); double numberOfYears = System::Convert::ToDouble(textBox3->Text); double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / pow(1 + monthlyInterestRate, numberOfYears * 12)); double totalPayment = monthlyPayment * numberOfYears * 12; monthlyPayment = floor(monthlyPayment * 100 + 0.5) / 100; totalPayment = floor(totalPayment * 100 + 0.5) / 100; textBox3->Text = System::Convert::ToString(monthlyPayment); //computes result, and displays values in text box //tbTotalPayment->Text = System::Convert::ToString(totalPayment); }*/ private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { if (textBox3->Text == ""){ double loanAmount = System::Convert::ToDouble(textBox1->Text); //converts the input value to double, if it wasn't already input as such double annualInterestRate = System::Convert::ToDouble(textBox2->Text); double payment = System::Convert::ToDouble(textBox4->Text); annualInterestRate = annualInterestRate / 1200; //computes the value of number of payments with the given information double top = log(payment / loanAmount) - log((payment / loanAmount) - annualInterestRate); double bottom = log(1 + annualInterestRate); double months = top / bottom; textBox3->Text = System::Convert::ToString(months); } else { errorProvider1->SetError(textBox3, "Please keep this blank to calculate the number of months."); } } private: System::Void errorProvider1_RightToLeftChanged(System::Object^ sender, System::EventArgs^ e) { } }; }