Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ГоловковИ.Е._12002108_Курсовая_работа.docx
Скачиваний:
5
Добавлен:
26.06.2024
Размер:
2.5 Mб
Скачать

Приложение b

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)

{

srand(time(NULL));

Int32 const razmP = 9;

Int32 lastRow = 0;

System::Int32^ S;

for (Int32 i = 0; i < 9; i++)

{

dataGridView1->Rows->Add();

if (checkBox1->Checked) dataGridView2->Rows->Add();

lastRow = dataGridView1->Rows->Count;

dataGridView1->Rows[lastRow - 1]->Cells[0]->Value = i + 1;

if (checkBox1->Checked) dataGridView2->Rows[lastRow - 1]->Cells[0]->Value = i + 1;

for (Int32 j = 0; j < razmP; j++)

{

dataGridView1->Rows[lastRow - 1]->Cells[j + 1]->Value = (Int32((i * 3 + i / 3 + j)) % (3 * 3) + 1);

if (checkBox1->Checked) dataGridView2->Rows[lastRow - 1]->Cells[j + 1]->Value = (Int32((i * 3 + i / 3 + j)) % (3 * 3) + 1);

}

}

lastRow = 0;

Int32 begS, endS;

for (Int32 povt = 0; povt < 1001; povt++) //Повторение перемешиваний

{

begS = (rand() % 3) * 3;

endS = begS + (rand() % 2 + 1);

for (Int32 i = 0; i < razmP; i++)

{

S = (System::Int32^)this->dataGridView1->Rows[i]->Cells[begS + 1]->Value;

dataGridView1->Rows[i]->Cells[begS + 1]->Value = dataGridView1->Rows[i]->Cells[endS + 1]->Value;

if (checkBox1->Checked)dataGridView2->Rows[i]->Cells[begS + 1]->Value = dataGridView2->Rows[i]->Cells[endS + 1]->Value;

dataGridView1->Rows[i]->Cells[endS + 1]->Value = S;

if (checkBox1->Checked)dataGridView2->Rows[i]->Cells[endS + 1]->Value = S;

}

for (Int32 i = 0; i < razmP; i++)

{

S = (System::Int32^)this->dataGridView1->Rows[begS]->Cells[i + 1]->Value;

dataGridView1->Rows[begS]->Cells[i + 1]->Value = dataGridView1->Rows[endS]->Cells[i + 1]->Value;

if (checkBox1->Checked)dataGridView2->Rows[begS]->Cells[i + 1]->Value = dataGridView2->Rows[endS]->Cells[i + 1]->Value;

dataGridView1->Rows[endS]->Cells[i + 1]->Value = S;

if (checkBox1->Checked)dataGridView2->Rows[endS]->Cells[i + 1]->Value = S;

}

}

Int32 kZero = 0;

Int32 ind = 0;

for (Int32 i = 0; i < razmP; i++)

{

for (Int32 j = 0; j < 4; j++)

{

ind = rand() % 9;

dataGridView1->Rows[i]->Cells[ind + 1]->Value = " ";

}

}

}

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)

{

dataGridView1->Rows->Clear();

dataGridView2->Rows->Clear();

}