private: // User declarations
bool __fastcall is_First(int x);
void __fastcall init_Random();
int **table_A;
int **table_B;
int **table_C;
int **table_D;
int **main_Table;
int *pool_Table;
int result_A;
int result_B;
int result_C;
int result_D;
void __fastcall init_Table();
void __fastcall destroy_Table();
bool __fastcall different_Value(int a, int b, int c, int d);
UnicodeString __fastcall max_Symbol(int a, int b, int c, int d);
void __fastcall prepare_Values(int a, int b, int c, int d);
void __fastcall TForm1::init_Random()
{
srand(time(NULL));
}
bool __fastcall TForm1::is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
void __fastcall TForm1::init_Table()
{
int i,j;
table_A=new int*[10];
table_B=new int*[10];
table_C=new int*[10];
table_D=new int*[10];
main_Table=new int*[10];
pool_Table=new int[100];
for(i=0;i<10;i++)
{
table_A[i]=new int[10];
table_B[i]=new int[10];
table_C[i]=new int[10];
table_D[i]=new int[10];
main_Table[i]=new int[10];
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
table_A[i][j]=0;
table_B[i][j]=0;
table_C[i][j]=0;
table_D[i][j]=0;
}
}
i=0;
j=1;
do
{
if(is_First(j))
{
pool_Table[i]=j;
++i;
}
++j;
} while(i<100);
}
void __fastcall TForm1::destroy_Table()
{
int i;
for(i=0;i<10;i++)
{
delete [] table_A[i];
delete [] table_B[i];
delete [] table_C[i];
delete [] table_D[i];
delete [] main_Table[i];
}
delete [] *table_A;
delete [] *table_B;
delete [] *table_C;
delete [] *table_D;
delete [] *main_Table;
delete pool_Table;
}
bool __fastcall TForm1::different_Value(int a, int b, int c, int d)
{
if(a!=b && a!=c && a!=d && b!=c && b!=d && c!=d)
return true;
else
return false;
}
UnicodeString __fastcall TForm1::max_Symbol(int a, int b, int c, int d)
{
if(a>b && a>c && a>d)
return "A";
if(b>a && b>c && b>d)
return "B";
if(c>a && c>b && c>d)
return "C";
if(d>a && d>b && d>c)
return "D";
}
void __fastcall TForm1::prepare_Values(int a, int b, int c, int d)
{
if(a>b && a>c && a>d)
result_A+=3;
if(b>a && b>c && b>d)
result_B+=3;
if(c>a && c>b && c>d)
result_C+=3;
if(d>a && d>b && d>c)
result_D+=3;
if(a>b && a>c && a<d)
result_A+=2;
if(a>b && a>d && a<c)
result_A+=2;
if(a>c && a>d && a<b)
result_A+=2;
if(a<b && a<c && a>d)
result_A+=1;
if(a<b && a<d && a>c)
result_A+=1;
if(a<c && a<d && a>b)
result_A+=1;
if(b>a && b>c && b<d)
result_B+=2;
if(b>a && b>d && b<c)
result_B+=2;
if(b>c && b>d && b<a)
result_B+=2;
if(b<a && b<c && b>d)
result_B+=1;
if(b<a && b<d && b>c)
result_B+=1;
if(b<c && b<c && b>a)
result_B+=1;
if(c>a && c>b && c<d)
result_C+=2;
if(c>a && c>d && c<b)
result_C+=2;
if(c>b && c>d && c<a)
result_C+=2;
if(c<a && c<b && c>d)
result_C+=1;
if(c<a && c<d && c>b)
result_C+=1;
if(c<b && c<d && c>a)
result_C+=1;
if(d>a && d>b && d<c)
result_D+=2;
if(d>a && d>c && d<b)
result_D+=2;
if(d>b && d>c && d<a)
result_D+=2;
if(d<a && d<b && d>c)
result_D+=1;
if(d<a && d<c && d>b)
result_D+=1;
if(d<b && d<c && d>a)
result_D+=1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
init_Random();
init_Table();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
int i,j,k;
result_A=result_B=result_C=result_D=0;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
;
while(!different_Value(table_A[i][j],table_B[i][j],table_C[i][j],table_D[i][j]))
{
k=rand()%100;
table_A[i][j]=pool_Table[k];
k=rand()%100;
table_B[i][j]=pool_Table[k];
k=rand()%100;
table_C[i][j]=pool_Table[k];
k=rand()%100;
table_D[i][j]=pool_Table[k];
}
StringGrid1->Cells[i][j]=IntToStr(table_A[i][j]);
StringGrid2->Cells[i][j]=IntToStr(table_B[i][j]);
StringGrid3->Cells[i][j]=IntToStr(table_C[i][j]);
StringGrid4->Cells[i][j]=IntToStr(table_D[i][j]);
StringGrid5->Cells[i][j]=max_Symbol(table_A[i][j],table_B[i][j],
table_C[i][j],table_D[i][j]);
prepare_Values(table_A[i][j],table_B[i][j],table_C[i][j],table_D[i][j]);
}
}
Edit1->Text=IntToStr(result_A);
Edit2->Text=IntToStr(result_B);
Edit3->Text=IntToStr(result_C);
Edit4->Text=IntToStr(result_D);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
destroy_Table();
Close();
}
Brak komentarzy:
Prześlij komentarz