Загрузка данных
MyForm.h
#pragma once
#include <string>
#include <msclr\marshal_cppstd.h>
#include "MyVector.h"
#include "TMatrix.h"
namespace Project2 {
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>
/// Сводка для MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::DataGridView^ dataGridView1;
protected:
private: System::Windows::Forms::Label^ label_equal;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::DataGridView^ dataGridView2;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::DataGridView^ dataGridView3;
private: System::Windows::Forms::Button^ button6;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Button^ button7;
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle87 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle88 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle89 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle90 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle91 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle92 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
this->label_equal = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->dataGridView2 = (gcnew System::Windows::Forms::DataGridView());
this->button4 = (gcnew System::Windows::Forms::Button());
this->button5 = (gcnew System::Windows::Forms::Button());
this->dataGridView3 = (gcnew System::Windows::Forms::DataGridView());
this->button6 = (gcnew System::Windows::Forms::Button());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->label5 = (gcnew System::Windows::Forms::Label());
this->button7 = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView2))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView3))->BeginInit();
this->SuspendLayout();
//
// dataGridView1
//
this->dataGridView1->AllowUserToAddRows = false;
this->dataGridView1->AllowUserToDeleteRows = false;
this->dataGridView1->BackgroundColor = System::Drawing::SystemColors::Control;
this->dataGridView1->BorderStyle = System::Windows::Forms::BorderStyle::None;
dataGridViewCellStyle87->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
dataGridViewCellStyle87->BackColor = System::Drawing::SystemColors::Control;
dataGridViewCellStyle87->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7.8F, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204)));
dataGridViewCellStyle87->ForeColor = System::Drawing::SystemColors::WindowText;
dataGridViewCellStyle87->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle87->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle87->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
this->dataGridView1->ColumnHeadersDefaultCellStyle = dataGridViewCellStyle87;
this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dataGridView1->ColumnHeadersVisible = false;
dataGridViewCellStyle88->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
dataGridViewCellStyle88->BackColor = System::Drawing::SystemColors::Window;
dataGridViewCellStyle88->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7.8F, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204)));
dataGridViewCellStyle88->ForeColor = System::Drawing::SystemColors::ControlText;
dataGridViewCellStyle88->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle88->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle88->WrapMode = System::Windows::Forms::DataGridViewTriState::False;
this->dataGridView1->DefaultCellStyle = dataGridViewCellStyle88;
this->dataGridView1->Location = System::Drawing::Point(24, 154);
this->dataGridView1->Name = L"dataGridView1";
this->dataGridView1->RowHeadersVisible = false;
this->dataGridView1->RowHeadersWidth = 51;
this->dataGridView1->RowTemplate->Height = 24;
this->dataGridView1->Size = System::Drawing::Size(290, 272);
this->dataGridView1->TabIndex = 0;
//
// label_equal
//
this->label_equal->AutoSize = true;
this->label_equal->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
this->label_equal->Location = System::Drawing::Point(779, 265);
this->label_equal->Name = L"label_equal";
this->label_equal->Size = System::Drawing::Size(37, 39);
this->label_equal->TabIndex = 3;
this->label_equal->Text = L"=";
//
// button1
//
this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
this->button1->Location = System::Drawing::Point(364, 168);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(53, 48);
this->button1->TabIndex = 4;
this->button1->Text = L"+";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// button2
//
this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 22));
this->button2->ForeColor = System::Drawing::SystemColors::ControlText;
this->button2->Location = System::Drawing::Point(364, 256);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(53, 48);
this->button2->TabIndex = 5;
this->button2->Text = L"-";
this->button2->TextAlign = System::Drawing::ContentAlignment::TopCenter;
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
//
// button3
//
this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
this->button3->Location = System::Drawing::Point(364, 339);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(53, 48);
this->button3->TabIndex = 6;
this->button3->Text = L"*";
this->button3->TextAlign = System::Drawing::ContentAlignment::BottomCenter;
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(889, 55);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(218, 22);
this->textBox1->TabIndex = 7;
this->textBox1->Leave += gcnew System::EventHandler(this, &MyForm::textBox1_Leave);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12));
this->label1->Location = System::Drawing::Point(832, 52);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(51, 25);
this->label1->TabIndex = 8;
this->label1->Text = L"Size";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12));
this->label2->Location = System::Drawing::Point(152, 115);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(26, 25);
this->label2->TabIndex = 9;
this->label2->Text = L"A";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12));
this->label3->Location = System::Drawing::Point(595, 115);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(25, 25);
this->label3->TabIndex = 10;
this->label3->Text = L"B";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12));
this->label4->Location = System::Drawing::Point(976, 115);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(52, 25);
this->label4->TabIndex = 11;
this->label4->Text = L"RES";
//
// dataGridView2
//
this->dataGridView2->AllowUserToAddRows = false;
this->dataGridView2->AllowUserToDeleteRows = false;
this->dataGridView2->BackgroundColor = System::Drawing::SystemColors::Control;
this->dataGridView2->BorderStyle = System::Windows::Forms::BorderStyle::None;
dataGridViewCellStyle89->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
dataGridViewCellStyle89->BackColor = System::Drawing::SystemColors::Control;
dataGridViewCellStyle89->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7.8F, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204)));
dataGridViewCellStyle89->ForeColor = System::Drawing::SystemColors::WindowText;
dataGridViewCellStyle89->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle89->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle89->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
this->dataGridView2->ColumnHeadersDefaultCellStyle = dataGridViewCellStyle89;
this->dataGridView2->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dataGridView2->ColumnHeadersVisible = false;
dataGridViewCellStyle90->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
dataGridViewCellStyle90->BackColor = System::Drawing::SystemColors::Window;
dataGridViewCellStyle90->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7.8F, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204)));
dataGridViewCellStyle90->ForeColor = System::Drawing::SystemColors::ControlText;
dataGridViewCellStyle90->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle90->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle90->WrapMode = System::Windows::Forms::DataGridViewTriState::False;
this->dataGridView2->DefaultCellStyle = dataGridViewCellStyle90;
this->dataGridView2->Location = System::Drawing::Point(467, 154);
this->dataGridView2->Name = L"dataGridView2";
this->dataGridView2->RowHeadersVisible = false;
this->dataGridView2->RowHeadersWidth = 51;
this->dataGridView2->RowTemplate->Height = 24;
this->dataGridView2->Size = System::Drawing::Size(290, 272);
this->dataGridView2->TabIndex = 12;
//
// button4
//
this->button4->Location = System::Drawing::Point(130, 40);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(77, 52);
this->button4->TabIndex = 13;
this->button4->Text = L"CHANGE";
this->button4->UseVisualStyleBackColor = true;
this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
//
// button5
//
this->button5->Location = System::Drawing::Point(569, 40);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(77, 52);
this->button5->TabIndex = 14;
this->button5->Text = L"CHANGE";
this->button5->UseVisualStyleBackColor = true;
this->button5->Click += gcnew System::EventHandler(this, &MyForm::button5_Click);
//
// dataGridView3
//
this->dataGridView3->AllowUserToAddRows = false;
this->dataGridView3->AllowUserToDeleteRows = false;
this->dataGridView3->BackgroundColor = System::Drawing::SystemColors::Control;
this->dataGridView3->BorderStyle = System::Windows::Forms::BorderStyle::None;
dataGridViewCellStyle91->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
dataGridViewCellStyle91->BackColor = System::Drawing::SystemColors::Control;
dataGridViewCellStyle91->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7.8F, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204)));
dataGridViewCellStyle91->ForeColor = System::Drawing::SystemColors::WindowText;
dataGridViewCellStyle91->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle91->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle91->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
this->dataGridView3->ColumnHeadersDefaultCellStyle = dataGridViewCellStyle91;
this->dataGridView3->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dataGridView3->ColumnHeadersVisible = false;
dataGridViewCellStyle92->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
dataGridViewCellStyle92->BackColor = System::Drawing::SystemColors::Window;
dataGridViewCellStyle92->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7.8F, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204)));
dataGridViewCellStyle92->ForeColor = System::Drawing::SystemColors::ControlText;
dataGridViewCellStyle92->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle92->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle92->WrapMode = System::Windows::Forms::DataGridViewTriState::False;
this->dataGridView3->DefaultCellStyle = dataGridViewCellStyle92;
this->dataGridView3->Location = System::Drawing::Point(851, 154);
this->dataGridView3->Name = L"dataGridView3";
this->dataGridView3->ReadOnly = true;
this->dataGridView3->RowHeadersVisible = false;
this->dataGridView3->RowHeadersWidth = 51;
this->dataGridView3->RowTemplate->Height = 24;
this->dataGridView3->Size = System::Drawing::Size(290, 272);
this->dataGridView3->TabIndex = 15;
//
// button6
//
this->button6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
this->button6->Location = System::Drawing::Point(364, 478);
this->button6->Name = L"button6";
this->button6->Size = System::Drawing::Size(53, 48);
this->button6->TabIndex = 16;
this->button6->Text = L"*";
this->button6->TextAlign = System::Drawing::ContentAlignment::BottomCenter;
this->button6->UseVisualStyleBackColor = true;
this->button6->Click += gcnew System::EventHandler(this, &MyForm::button6_Click);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(489, 489);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(131, 22);
this->textBox2->TabIndex = 17;
//
// label5
//
this->label5->AutoSize = true;
this->label5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14));
this->label5->Location = System::Drawing::Point(454, 482);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(29, 29);
this->label5->TabIndex = 18;
this->label5->Text = L"K";
//
// button7
//
this->button7->Location = System::Drawing::Point(636, 478);
this->button7->Name = L"button7";
this->button7->Size = System::Drawing::Size(77, 52);
this->button7->TabIndex = 19;
this->button7->Text = L"CHANGE";
this->button7->UseVisualStyleBackColor = true;
this->button7->Click += gcnew System::EventHandler(this, &MyForm::button7_Click);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1249, 589);
this->Controls->Add(this->button7);
this->Controls->Add(this->label5);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->button6);
this->Controls->Add(this->dataGridView3);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->dataGridView2);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->label_equal);
this->Controls->Add(this->dataGridView1);
this->Name = L"MyForm";
this->Text = L"MyForm";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView2))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView3))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
int N = 0;
private: System::Void textBox1_Leave(System::Object^ sender, System::EventArgs^ e) {
System::String^ text1 = textBox1->Text;
std::string s1 = msclr::interop::marshal_as<std::string>(text1);
N = stoi(s1);
dataGridView1->ColumnCount = N;
dataGridView1->RowCount = N;
dataGridView1->AutoSizeColumnsMode = System::Windows::Forms::DataGridViewAutoSizeColumnsMode::Fill;
int ht1 = dataGridView1->Height;
int row_ht1 = ht1 / N;
for (int i = 0; i < N; i++) {
dataGridView1->Rows[i]->Height = row_ht1;
}
dataGridView2->ColumnCount = N;
dataGridView2->RowCount = N;
dataGridView2->AutoSizeColumnsMode = System::Windows::Forms::DataGridViewAutoSizeColumnsMode::Fill;
int ht2 = dataGridView2->Height;
int row_ht2 = ht2 / N;
for (int i = 0; i < N; i++) {
dataGridView2->Rows[i]->Height = row_ht2;
}
dataGridView3->ColumnCount = N;
dataGridView3->RowCount = N;
dataGridView3->AutoSizeColumnsMode = System::Windows::Forms::DataGridViewAutoSizeColumnsMode::Fill;
int ht3 = dataGridView3->Height;
int row_ht3 = ht3 / N;
for (int i = 0; i < N; i++) {
dataGridView3->Rows[i]->Height = row_ht3;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i > j) {
dataGridView1->Rows[i]->Cells[j]->Value = 0;
dataGridView1->Rows[i]->Cells[j]->ReadOnly = true;
dataGridView2->Rows[i]->Cells[j]->Value = 0;
dataGridView2->Rows[i]->Cells[j]->ReadOnly = true;
}
}
}
}
TMatrix *tm1 = nullptr;
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
if (N != 0) {
if (tm1 != nullptr) {
delete tm1;
}
tm1 = new TMatrix(N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i <= j) {
if (dataGridView1->Rows[i]->Cells[j]->Value == nullptr) {
(*tm1)[i][j] = 0;
}
else {
int numb;
System::String^ txt = dataGridView1->Rows[i]->Cells[j]->Value->ToString();
if (System::Int32::TryParse(txt, numb)) {
}
else {
numb = 0;
}
(*tm1)[i][j] = numb;
}
}
}
}
}
}
TMatrix *tm2 = nullptr;
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
if (N != 0) {
if (tm2 != nullptr) {
delete tm2;
}
tm2 = new TMatrix(N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i <= j) {
if (dataGridView2->Rows[i]->Cells[j]->Value == nullptr) {
(*tm2)[i][j] = 0;
}
else {
int numb;
System::String^ txt = dataGridView2->Rows[i]->Cells[j]->Value->ToString();
if (System::Int32::TryParse(txt, numb)) {
}
else {
numb = 0;
}
(*tm2)[i][j] = numb;
}
}
}
}
}
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
TMatrix tm3 = *tm1 + *tm2;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dataGridView3->Rows[i]->Cells[j]->Value = tm3[i][j];
}
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
TMatrix tm4 = *tm1 - *tm2;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dataGridView3->Rows[i]->Cells[j]->Value = tm4[i][j];
}
}
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
TMatrix tm5 = *tm1 * *tm2;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dataGridView3->Rows[i]->Cells[j]->Value = tm5[i][j];
}
}
}
int K = 0;
private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e) {
System::String^ text2 = textBox2->Text;
std::string s2 = msclr::interop::marshal_as<std::string>(text2);
K = stoi(s2);
}
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
TMatrix tm6 = *tm1 * K;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dataGridView3->Rows[i]->Cells[j]->Value = tm6[i][j];
}
}
}
};
}
----------
TMatrix
#pragma once
#include "MyVector.h"
class TMatrix {
private:
MyVector<MyVector<int>> Matr;
int size_m;
public:
TMatrix(int size = 0) {
size_m = size;
Matr = MyVector<MyVector<int>>(size_m);
for (int i = 0; i < size_m; i++) {
Matr[i] = MyVector<int>(size_m - i, i);
for (int j = 0; j < size_m - i; j++) {
Matr[i][j] = 0;
}
}
}
~TMatrix() {}
TMatrix(const TMatrix& tmp) {
size_m = tmp.size_m;
Matr = tmp.Matr;
}
TMatrix& operator=(const TMatrix& tmp) {
size_m = tmp.size_m;
Matr = tmp.Matr;
return *this;
}
MyVector<int>& operator[](int k) {
static MyVector<int> res(0);
if (k >= 0 && k < size_m) {
return Matr[k];
}
else {
return res;
}
}
TMatrix operator+(TMatrix tmp) {
TMatrix res(size_m);
if (size_m == tmp.size_m) {
res.Matr = Matr + tmp.Matr;
}
return res;
}
TMatrix operator-(TMatrix tmp) {
TMatrix res(size_m);
if (size_m == tmp.size_m) {
res.Matr = Matr - tmp.Matr;
}
return res;
}
TMatrix operator*(int k) {
TMatrix res(size_m);
res.Matr = Matr * k;
return res;
}
TMatrix operator*(TMatrix tmp) {
TMatrix res(*this);
if (size_m == tmp.size_m) {
for (int i = 0; i < size_m; i++) {
for (int j = i; j < size_m; j++) {
res[i][j] = 0;
for (int k = i; k <= j; k++) {
res[i][j] = res[i][j] + (*this)[i][k] * tmp[k][j];
}
}
}
}
return res;
}
};
------------
MyVector
#pragma once
template<typename T>
class MyVector {
private:
T* mem;
int size;
int start;
public:
MyVector(int tsize = 10, int tstart = 0) {
size = tsize;
start = tstart;
mem = new T[size];
for (int i = 0; i < size; i++) {
mem[i] = T(0);
}
}
MyVector<T>& operator=(const MyVector<T>& tmp) {
if ((size != tmp.size) || start != tmp.start) {
if (size != 0) {
delete[] mem;
}
size = tmp.size;
mem = new T[tmp.size];
}
start = tmp.start;
for (int i = 0; i < size; i++) {
mem[i] = tmp.mem[i];
}
return *this;
}
~MyVector() {
delete[] mem;
}
MyVector(const MyVector<T>& tmp) {
size = tmp.size;
start = tmp.start;
mem = new T[size];
for (int i = 0; i < size; i++) {
mem[i] = tmp.mem[i];
}
}
T& operator[] (int j) {
static T res(0);
if (j < start || j >= size + start) {
return res;
}
else {
return mem[j - start];
}
}
int getSize() {
return size;
}
int getStart() {
return start;
}
T* getmem() {
return mem;
}
MyVector<T> operator+ (const MyVector<T>& tmp) {
MyVector<T> res(*this);
if (start == tmp.start && size == tmp.size) {
for (int i = 0; i < size; i++) {
res.mem[i] = mem[i] + tmp.mem[i];
}
}
return res;
}
MyVector<T> operator- (const MyVector<T>& tmp) {
MyVector<T> res(*this);
if (start == tmp.start && size == tmp.size) {
for (int i = 0; i < size; i++) {
res.mem[i] = mem[i] - tmp.mem[i];
}
}
return res;
}
MyVector<T> operator* (int k) {
MyVector<T> res(*this);
for (int i = 0; i < size; i++) {
res.mem[i] = mem[i] * k;
}
return res;
}
T operator* (const MyVector<T>& tmp) {
T res(0);
if ((start == tmp.start) && (size == tmp.size)) {
for (int i = 0; i < size; i++) {
res += mem[i] * tmp.mem[i];
}
}
return res;
}
};