My file with date - "date.h"
#include <iostream>
#define size 10
using namespace std;
int **main_tab;
int **tab_temp2;
int **tab_temp3;
void initialization_Tab()
{
int i;
//use in functions FormCreate
main_tab=new int *[size];
tab_temp2=new int *[size];
tab_temp3=new int *[size];
for(i=0;i<size;i++)
{
main_tab[i]=new int[size];
tab_temp2[i]=new int[size];
tab_temp3[i]=new int[size];
}
}
void deleyted_Tab()
{
//use in function click button Close
int i;
for(i=0;i<size;i++)
{
delete [] main_tab[i];
delete tab_temp2[i];
delete tab_temp3[i];
}
delete [] *main_tab;
delete [] *tab_temp2;
delete [] *tab_temp3;
}
My functions and libraries:
#include <vcl.h>
#include <stdlib.h>
#include <time.h>
#include <time.h>
#include "date.h"
void __fastcall TForm1::init_Random()
{
srand(time(NULL));
}
AnsiString __fastcall TForm1:: char_for_Value(int x)
{
if(x>0 && x<3)
return "A";
else if(x>2 && x<5)
return "B";
else if(x>4 && x<7)
return "C";
else if(x>6 && x<9)
return "D";
else return "E";
}
My form in C++ Builder:
Code:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i,j;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
main_tab[i][j]=rand()%10+1;
StringGrid1->Cells[i][j]=IntToStr(main_tab[i][j]);
if(main_tab[i][j]%2==0)
tab_temp2[i][j]=0;
else
tab_temp2[i][j]=1;
StringGrid2->Cells[i][j]=IntToStr(tab_temp2[i][j]);
}
}
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
tab_temp3[i][j]=main_tab[i][j];
if(i-1>0)
tab_temp3[i][j]+=main_tab[i-1][j];
if((i-1)>0 && (j-1)>0)
tab_temp3[i][j]+=main_tab[i-1][j-1];
if(j-1>0)
tab_temp3[i][j]+=main_tab[i][j-1];
if((i+1)<size && (j-1)>0)
tab_temp3[i][j]+=main_tab[i+1][j-1];
if(i+1<size)
tab_temp3[i][j]+=main_tab[i+1][j];
if((i+1)<size && (j+1)<size)
tab_temp3[i][j]+=main_tab[i+1][j+1];
if(j+1<size)
tab_temp3[i][j]+=main_tab[i][j+1];
if((i-1)>0 && (j+1)<size)
tab_temp3[i][j]+=main_tab[i-1][j+1];
StringGrid3->Cells[i][j]=IntToStr(tab_temp3[i][j]);
StringGrid4->Cells[i][j]=char_for_Value(main_tab[i][j]);
}
}
}
And program running:
Brak komentarzy:
Prześlij komentarz