date.h
#pragma once
int tab1[40];
int tab2[40];
int tab3[40];
void m_Isort(int* tab, int s)
{
int i, j, k;
for (i = 1; i < s; i++)
{
j = i;
k = tab[j];
while ((j > 0) && (tab[j - 1] > k))
{
tab[j] = tab[j - 1];
j--;
}
tab[j] = k;
}
}
Form1.h
#pragma once
#include <stdlib.h>
#include <time.h>
#include "date.h"
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
int i;
srand(time(NULL));
dataGridView1->ColumnCount = 40;
dataGridView1->RowCount = 2;
for (i = 0; i < 40; i++)
dataGridView1->Columns[i]->Width = 30;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int max_X = panel1->Width;
int max_Y = panel1->Height;
int min_X, min_Y,i,j,k,l;
min_X = min_Y = 1;
Graphics^ gr = panel1->CreateGraphics();
Pen^ my_Pen = gcnew Pen(System::Drawing::Color::Blue);
array<System::Drawing::PointF>^ xy = gcnew array<System::Drawing::PointF>(40);
my_Pen->Width = 3;
for (i = 0; i < 40; i++)
{
k = rand() % max_X + min_X;
l = rand() % max_Y + min_Y;
tab1[i] = k;
tab2[i] = l;
}
m_Isort(tab1, 40);
m_Isort(tab2, 40);
for (i = 0; i < 40; i++)
tab3[i] = max_Y - tab2[i];
for (i = 0; i < 40; i++)
{
dataGridView1->Rows[0]->Cells[i]->Value = tab1[i].ToString();
dataGridView1->Rows[1]->Cells[i]->Value = tab2[i].ToString();
xy[i].X = tab1[i];
xy[i].Y = tab3[i];
}
gr->DrawCurve(my_Pen, xy);
}
};
}
Brak komentarzy:
Prześlij komentarz