КАТЕГОРИИ:
АстрономияБиологияГеографияДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРиторикаСоциологияСпортСтроительствоТехнологияФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника
|
Стадии и этапы разработки
Алгоритм решения задачи 1.Вводим количество узлов интерполяции (N). 2.Вводим элементы массива X и Y. 3.Вычислениям шаг(h), где h=x[1]-x[0]. 4. Листинг программы #include "Interpolation.h" #pragma once namespace InterpolationLagrange {
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> /// Сводка для Form1 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: добавьте код конструктора // } protected: /// <summary> /// Освободить все используемые ресурсы. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::GroupBox^ groupBox1; protected: private: System::Windows::Forms::Button^ button2; private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::TextBox^ textBox2; private: System::Windows::Forms::TextBox^ textBox1; private: System::Windows::Forms::Label^ label2; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::GroupBox^ groupBox2; private: System::Windows::Forms::TextBox^ textBox3; private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::DataGridView^ dataGridView1; private: System::Windows::Forms::DataGridViewTextBoxColumn^ X; private: System::Windows::Forms::DataGridViewTextBoxColumn^ Y;
private: /// <summary> /// Требуется переменная конструктора. /// </summary> System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code /// <summary> /// Обязательный метод для поддержки конструктора - не изменяйте /// содержимое данного метода при помощи редактора кода. /// </summary> void InitializeComponent(void) { this->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); this->button2 = (gcnew System::Windows::Forms::Button()); this->button1 = (gcnew System::Windows::Forms::Button()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->label2 = (gcnew System::Windows::Forms::Label()); this->label1 = (gcnew System::Windows::Forms::Label()); this->groupBox2 = (gcnew System::Windows::Forms::GroupBox()); this->textBox3 = (gcnew System::Windows::Forms::TextBox()); this->label3 = (gcnew System::Windows::Forms::Label()); this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView()); this->X = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); this->Y = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); this->groupBox1->SuspendLayout(); this->groupBox2->SuspendLayout(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->BeginInit(); this->SuspendLayout(); // // groupBox1 // this->groupBox1->Controls->Add(this->button2); this->groupBox1->Controls->Add(this->button1); this->groupBox1->Controls->Add(this->textBox2); this->groupBox1->Controls->Add(this->textBox1); this->groupBox1->Controls->Add(this->label2); this->groupBox1->Controls->Add(this->label1); this->groupBox1->Location = System::Drawing::Point(15, 15); this->groupBox1->Name = L"groupBox1"; this->groupBox1->Size = System::Drawing::Size(250, 220); this->groupBox1->TabIndex = 0; this->groupBox1->TabStop = false; this->groupBox1->Text = L" Ввод данных "; // // button2 // this->button2->Location = System::Drawing::Point(13, 180); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(220, 23); this->button2->TabIndex = 5; this->button2->Text = L"Найти решение"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // button1 // this->button1->Location = System::Drawing::Point(205, 25); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(39, 23); this->button1->TabIndex = 4; this->button1->Text = L"Ok"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // textBox2 // this->textBox2->Location = System::Drawing::Point(78, 147); this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(121, 20); this->textBox2->TabIndex = 3; this->textBox2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::textBox2_KeyPress); // // textBox1 // this->textBox1->Location = System::Drawing::Point(124, 27); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(75, 20); this->textBox1->TabIndex = 2; this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::textBox1_KeyPress); // // label2 // this->label2->AutoSize = true; this->label2->Location = System::Drawing::Point(10, 150); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(62, 13); this->label2->TabIndex = 1; this->label2->Text = L"Введите X:"; // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(10, 30); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(108, 13); this->label1->TabIndex = 0; this->label1->Text = L"Введите к-во узлов:"; // // groupBox2 // this->groupBox2->Controls->Add(this->textBox3); this->groupBox2->Controls->Add(this->label3); this->groupBox2->Location = System::Drawing::Point(15, 240); this->groupBox2->Name = L"groupBox2"; this->groupBox2->Size = System::Drawing::Size(250, 60); this->groupBox2->TabIndex = 1; this->groupBox2->TabStop = false; this->groupBox2->Text = L" Результат "; // // textBox3 // this->textBox3->Location = System::Drawing::Point(55, 27); this->textBox3->Name = L"textBox3"; this->textBox3->ReadOnly = true; this->textBox3->Size = System::Drawing::Size(150, 20); this->textBox3->TabIndex = 1; // // label3 // this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(15, 30); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(34, 13); this->label3->TabIndex = 0; this->label3->Text = L"P(x) ="; // // dataGridView1 // this->dataGridView1->AllowUserToAddRows = false; this->dataGridView1->AllowUserToDeleteRows = false; this->dataGridView1->AllowUserToResizeColumns = false; this->dataGridView1->AllowUserToResizeRows = false; this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize; this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^ >(2) {this->X, this->Y}); this->dataGridView1->Location = System::Drawing::Point(275, 15); this->dataGridView1->Name = L"dataGridView1"; this->dataGridView1->RowHeadersVisible = false; this->dataGridView1->ScrollBars = System::Windows::Forms::ScrollBars::Vertical; this->dataGridView1->Size = System::Drawing::Size(154, 285); this->dataGridView1->TabIndex = 2; // // X // this->X->Frozen = true; this->X->HeaderText = L"X"; this->X->Name = L"X"; this->X->SortMode = System::Windows::Forms::DataGridViewColumnSortMode::NotSortable; this->X->Width = 75; // // Y // this->Y->Frozen = true; this->Y->HeaderText = L"Y"; this->Y->Name = L"Y"; this->Y->SortMode = System::Windows::Forms::DataGridViewColumnSortMode::NotSortable; this->Y->Width = 75; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(444, 312); this->Controls->Add(this->dataGridView1); this->Controls->Add(this->groupBox2); this->Controls->Add(this->groupBox1); this->Name = L"Form1"; this->Text = L"Интерполяция методом Лагранжа"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); this->groupBox1->ResumeLayout(false); this->groupBox1->PerformLayout(); this->groupBox2->ResumeLayout(false); this->groupBox2->PerformLayout(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->EndInit(); this->ResumeLayout(false);
} #pragma endregion String^ decSeparator; private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { decSeparator = Globalization::NumberFormatInfo::CurrentInfo->NumberDecimalSeparator; } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if(!int::TryParse(textBox1->Text,(int)n)) { MessageBox::Show(L"Ошибка! Проверте правильность ввода параметра - n"); return; } n = int::Parse(textBox1->Text); if(!n) { MessageBox::Show(L"Ошибка! Проверте правильность ввода n > 0"); return; } while(dataGridView1->RowCount != 0) // Удалим все строки из dataGridView1 dataGridView1->Rows->RemoveAt(0); for(int i=0; i!=n; ++i) // Добавить n строк dataGridView1->Rows->Add(); } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { if(!int::TryParse(textBox1->Text,(int)n)) { MessageBox::Show(L"Ошибка! Проверте правильность ввода параметра - n"); return; } n = int::Parse(textBox1->Text); if(!n) { MessageBox::Show(L"Ошибка! Проверте правильность ввода n > 0"); return; } double x = 0.0; if(!Double::TryParse(textBox2->Text,x)) { MessageBox::Show(L"Ошибка! Проверте правильность ввода параметра - x"); return; } Points *points = new Points[n]; for(unsigned int i=0; i!=n; ++i) { String ^str; str = dataGridView1->Rows[i]->Cells[0]->FormattedValue->ToString(); if(!Double::TryParse(str,points[i].x)) { MessageBox::Show(L"Ошибка! Проверте правильность ввода узлов"); return; } str = dataGridView1->Rows[i]->Cells[1]->FormattedValue->ToString(); if(!Double::TryParse(str,points[i].y)) { MessageBox::Show(L"Ошибка! Проверте правильность ввода узлов"); return; } } textBox3->Text = interpolation.Lagrange(x, points, n).ToString(); delete[] points; } private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { if(Char::IsDigit(e->KeyChar)) return; if(e->KeyChar == (char)Keys::Back) return; e->Handled = true; } private: System::Void textBox2_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { bool flDecSeparator = false; if (!(textBox2->Text->Length) && (e->KeyChar == '-')) return; if(Char::IsDigit(e->KeyChar)) return; if(e->KeyChar == (char)Keys::Back) return; if(textBox2->Text->IndexOf(decSeparator) != -1) flDecSeparator = true; if(flDecSeparator) { e->Handled = true; return; } if(e->KeyChar.ToString() == decSeparator) return; e->Handled = true; } }; }
|