Смекни!
smekni.com

Калькулятор для матриць (стр. 2 из 3)

Cловник понять використаних в програмі:

Button – кнопка .

Label – надпис .

TextBox– текстове вікно .

Length – розмір, довжина масиву .

MainMenu – головне меню .

MenuItem – пункт меню .


Лістинг програми

#pragma once

namespace nn

{

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>

/// 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.

/// </summary>

public __gc class Form1 : public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

}

protected:

void Dispose(Boolean disposing)

{

if (disposing && components)

{

components->Dispose();

}

__super::Dispose(disposing);

}

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::Label * label5;

private: System::Windows::Forms::Label * label6;

private: System::Windows::Forms::TextBox * textBox1;

private: System::Windows::Forms::TextBox * textBox2;

private: System::Windows::Forms::TextBox * textBox3;

private: System::Windows::Forms::TextBox * textBox4;

private: System::Windows::Forms::TextBox * textBox5;

private: System::Windows::Forms::TextBox * textBox6;

private: System::Windows::Forms::Button * button1;

private: System::Windows::Forms::Button * button2;

private: System::Windows::Forms::Button * button3;

private: System::Windows::Forms::Button * button4;

private: System::Windows::Forms::Button * button5;

private: System::Windows::Forms::Button * button6;

private: System::Windows::Forms::Button * button7;

private: System::Windows::Forms::Button * button8;

private: System::Windows::Forms::MainMenu * mainMenu1;

private: System::Windows::Forms::MenuItem * menuItem1;

private: System::Windows::Forms::MenuItem * menuItem2;

private: System::Windows::Forms::MenuItem * menuItem3;

private: System::Windows::Forms::MenuItem * menuItem4;

private: System::Windows::Forms::MenuItem * menuItem5;

private: System::Windows::Forms::MenuItem * menuItem6;

private: System::Windows::Forms::MenuItem * menuItem7;

private: System::Windows::Forms::MenuItem * menuItem8;

private: System::Windows::Forms::MenuItem * menuItem9;

private: System::Windows::Forms::MenuItem * menuItem10;

private: System::Windows::Forms::MenuItem * menuItem11;

private: System::Windows::Forms::Button * button10;

private: System::Windows::Forms::Button * button11;

private: System::Windows::Forms::MenuItem * menuItem12;

private: System::Windows::Forms::Button * button9;

private:

////////////////////////////////////////////////////////

double DET(double **X,int n)

{

double **T,kk=0;

int i,j,l,e=1;

if(n==1)return X[0][0];

if(n==2)return X[0][0]*X[1][1]-X[1][0]*X[0][1];

T=new double*[n-1];

for(i=0;i<n-1;i++)

T[i]=new double[n-1];

for(l=0;l<n;l++)

{

for(j=0;j<l;j++)

for(i=0;i<n-1;i++)

T[i][j]=X[i+1][j];

for(j=l+1;j<n;j++)

for(i=0;i<n-1;i++)

{

T[i][j-1]=X[i][j+1];

kk+=DET(T,n-1)*X[0][l]*e;

e*=-1;

}

}

return kk;

}

/////////////////////////////////////////////////////////

double ALG_DOP(double **X,int n,int r,int c)

{

double **T,k;

int i,j,e=1,ee=1;

if(n==1)

return X[0][0];

if(n==2)

{

if((r+c)%2==1)

{ee=-1;}

}

return ee;

T=new double*[n-1];

for(i=0;i<n-1;i++)

T[i]=new double[n-1];

for(i=0;i<r;i++)

{

for(j=0;j<c;j++)

T[i][j]=X[i][j];

for(j=c+1;j<n;j++)

T[i][j-1]=X[i][j];

}

for(i=r+1;i<n;i++)

{

for(j=0;j<c;j++)

T[i-1][j]=X[i][j];

for(j=c+1;j<n;j++)

T[i-1][j-1]=X[i][j];

}

k=DET(T,n-1);

if((r+c)%2==1)

e=-1;

return k*e;

}

////////////////////////////////////////////////////

String* CNV_ARRAY(double **X,int n)

{

int i,j;

String *s;

String *ss;

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

ss=Convert::ToString(X[i][j]);

s=s->Concat(s,ss," ");

}

s=s->Concat(s,"&bsol;n&bsol;0");

}

return s;

}

////////////////////////////////////////////////////

void GET_ARRAY(String *text,double **X,int n)

{

int i,j,k=0,p=0;

double dd;

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

while(((p+k)<text->Length)&&(text->Chars[p+k]!=wchar_t(' '))&&(text->Chars[p+k]!='&bsol;n')){k++;}

dd=Convert::ToDouble(text->Substring(p,k));

X[i][j]=dd;

p=p+k+1;

k=0;

}

}

}

//////////////////////////////////////////////////////

void TRANSP_ARRAY(double **X,int n)

{

int i,j;

double ca;

for(i=0;i<n-1;i++)

for(j=i+1;j<n;j++)

{

ca=X[i][j];

X[i][j]=X[j][i];

X[j][i]=ca;

}

}

//////////////////////////////////////////////////////

double TRACE(double **X,int n)

{

int i,j;

double tt=0;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

{

if(i==j)

tt+=X[i][j];

}

return tt;

}

////////////////////////////////////////////////////

/// <summary>

/// Required designer variable.

/// </summary>

System::ComponentModel::Container * components;

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

void InitializeComponent(void)

{

this->label1 = new System::Windows::Forms::Label();

this->label2 = new System::Windows::Forms::Label();

this->label3 = new System::Windows::Forms::Label();

this->label4 = new System::Windows::Forms::Label();

this->label5 = new System::Windows::Forms::Label();

this->label6 = new System::Windows::Forms::Label();

this->textBox1 = new System::Windows::Forms::TextBox();

this->textBox2 = new System::Windows::Forms::TextBox();

this->textBox3 = new System::Windows::Forms::TextBox();

this->textBox4 = new System::Windows::Forms::TextBox();

this->textBox5 = new System::Windows::Forms::TextBox();

this->textBox6 = new System::Windows::Forms::TextBox();

this->button1 = new System::Windows::Forms::Button();

this->button2 = new System::Windows::Forms::Button();

this->button3 = new System::Windows::Forms::Button();

this->button4 = new System::Windows::Forms::Button();

this->button5 = new System::Windows::Forms::Button();

this->button6 = new System::Windows::Forms::Button();

this->button7 = new System::Windows::Forms::Button();

this->button8 = new System::Windows::Forms::Button();

this->button9 = new System::Windows::Forms::Button();

this->mainMenu1 = new System::Windows::Forms::MainMenu();

this->menuItem1 = new System::Windows::Forms::MenuItem();

this->menuItem2 = new System::Windows::Forms::MenuItem();

this->menuItem3 = new System::Windows::Forms::MenuItem();

this->menuItem4 = new System::Windows::Forms::MenuItem();

this->menuItem5 = new System::Windows::Forms::MenuItem();

this->menuItem6 = new System::Windows::Forms::MenuItem();

this->menuItem7 = new System::Windows::Forms::MenuItem();

this->menuItem8 = new System::Windows::Forms::MenuItem();

this->menuItem9 = new System::Windows::Forms::MenuItem();

this->menuItem10 = new System::Windows::Forms::MenuItem();

this->menuItem11 = new System::Windows::Forms::MenuItem();

this->button10 = new System::Windows::Forms::Button();

this->button11 = new System::Windows::Forms::Button();

this->menuItem12 = new System::Windows::Forms::MenuItem();

this->SuspendLayout();

//

// label1

//

this->label1->Location = System::Drawing::Point(16, 88);

this->label1->Name = S"label1";

this->label1->Size = System::Drawing::Size(24, 23);

this->label1->TabIndex = 15;

this->label1->Text = S"A:";

this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;

//

// label2

//

this->label2->Location = System::Drawing::Point(8, 192);

this->label2->Name = S"label2";

this->label2->Size = System::Drawing::Size(32, 23);

this->label2->TabIndex = 16;

this->label2->Text = S"B:";

this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;

//

// label3

//

this->label3->Location = System::Drawing::Point(352, 192);

this->label3->Name = S"label3";

this->label3->Size = System::Drawing::Size(32, 23);

this->label3->TabIndex = 17;

this->label3->Text = S"C:";

this->label3->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;

//

// label4

//

this->label4->Location = System::Drawing::Point(16, 16);

this->label4->Name = S"label4";

this->label4->Size = System::Drawing::Size(48, 23);

this->label4->TabIndex = 18;

this->label4->Text = S"SIZE:";

this->label4->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;

//

// label5

//

this->label5->Location = System::Drawing::Point(152, 16);

this->label5->Name = S"label5";

this->label5->Size = System::Drawing::Size(48, 23);

this->label5->TabIndex = 19;

this->label5->Text = S"CONST:";

this->label5->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;

//

// label6

//

this->label6->Location = System::Drawing::Point(176, 216);

this->label6->Name = S"label6";

this->label6->Size = System::Drawing::Size(56, 23);

this->label6->TabIndex = 20;

this->label6->Text = S"REZULT:";

this->label6->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;

//

// textBox1

//

this->textBox1->AutoSize = false;

this->textBox1->BackColor = System::Drawing::Color::Lavender;

this->textBox1->Location = System::Drawing::Point(48, 56);

this->textBox1->Name = S"textBox1";

this->textBox1->Size = System::Drawing::Size(100, 80);

this->textBox1->TabIndex = 1;

this->textBox1->Text = S"";

this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;

//

// textBox2

//

this->textBox2->AutoSize = false;

this->textBox2->BackColor = System::Drawing::Color::Lavender;

this->textBox2->Location = System::Drawing::Point(48, 160);

this->textBox2->Name = S"textBox2";

this->textBox2->Size = System::Drawing::Size(100, 80);

this->textBox2->TabIndex = 2;

this->textBox2->Text = S"";

this->textBox2->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;

//

// textBox3

//

this->textBox3->AutoSize = false;

this->textBox3->BackColor = System::Drawing::Color::AliceBlue;

this->textBox3->Location = System::Drawing::Point(392, 160);

this->textBox3->Name = S"textBox3";

this->textBox3->Size = System::Drawing::Size(100, 80);

this->textBox3->TabIndex = 4;

this->textBox3->Text = S"";

this->textBox3->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;

//

// textBox4

//

this->textBox4->AutoSize = false;

this->textBox4->BackColor = System::Drawing::Color::LavenderBlush;

this->textBox4->Location = System::Drawing::Point(64, 16);

this->textBox4->Name = S"textBox4";

this->textBox4->Size = System::Drawing::Size(64, 20);

this->textBox4->TabIndex = 0;

this->textBox4->Text = S"";

this->textBox4->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;

// textBox5

//

this->textBox5->AutoSize = false;

this->textBox5->BackColor = System::Drawing::Color::LavenderBlush;

this->textBox5->Location = System::Drawing::Point(208, 16);

this->textBox5->Name = S"textBox5";

this->textBox5->Size = System::Drawing::Size(40, 20);

this->textBox5->TabIndex = 3;

this->textBox5->Text = S"";

this->textBox5->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;

//

// textBox6

//

this->textBox6->AutoSize = false;

this->textBox6->BackColor = System::Drawing::Color::AliceBlue;

this->textBox6->Location = System::Drawing::Point(240, 208);

this->textBox6->Name = S"textBox6";

this->textBox6->Size = System::Drawing::Size(48, 32);

this->textBox6->TabIndex = 5;

this->textBox6->Text = S"";

this->textBox6->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;

//

// button1

//

this->button1->BackColor = System::Drawing::Color::LightSkyBlue;

this->button1->Location = System::Drawing::Point(272, 8);

this->button1->Name = S"button1";

this->button1->Size = System::Drawing::Size(32, 23);

this->button1->TabIndex = 6;

this->button1->Text = S"*";

this->button1->Click += new System::EventHandler(this, button1_Click);

//

// button2

//

this->button2->BackColor = System::Drawing::Color::LightSkyBlue;

this->button2->Location = System::Drawing::Point(344, 8);

this->button2->Name = S"button2";

this->button2->Size = System::Drawing::Size(32, 23);

this->button2->TabIndex = 7;

this->button2->Text = S"+";

this->button2->Click += new System::EventHandler(this, button2_Click);

//

// button3

//

this->button3->BackColor = System::Drawing::Color::LightSkyBlue;

this->button3->Location = System::Drawing::Point(432, 8);

this->button3->Name = S"button3";

this->button3->Size = System::Drawing::Size(32, 23);

this->button3->TabIndex = 8;

this->button3->Text = S"--";

this->button3->Click += new System::EventHandler(this, button3_Click);

//

// button4

//

this->button4->BackColor = System::Drawing::Color::LightSkyBlue;

this->button4->Location = System::Drawing::Point(264, 48);

this->button4->Name = S"button4";

this->button4->Size = System::Drawing::Size(48, 23);

this->button4->TabIndex = 9;

this->button4->Text = S"*const";

this->button4->Click += new System::EventHandler(this, button4_Click);

//

// button5

//

this->button5->BackColor = System::Drawing::Color::LightSkyBlue;

this->button5->Location = System::Drawing::Point(264, 96);

this->button5->Name = S"button5";

this->button5->Size = System::Drawing::Size(48, 23);

this->button5->TabIndex = 10;