int main_Tab[20],min_Tab[20],max_Tab[20];
double aver_Tab[20];
void __fastcall min_Sort(int *tab, int s);
void __fastcall max_Sort(int *tab, int s);
int __fastcall minus_Plus(int value);
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
srand(time(NULL));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
int __fastcall TForm1::minus_Plus(int value)
{
int temp;
temp=1+rand()%20;
if(temp%2==0)
return value;
else
return value*-1;
}
void __fastcall TForm1::min_Sort(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;
}
}
void __fastcall TForm1::max_Sort(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;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
for(i=0;i<20;i++)
{
main_Tab[i]=1+rand()%100;
main_Tab[i]=minus_Plus(main_Tab[i]);
min_Tab[i]=main_Tab[i];
max_Tab[i]=main_Tab[i];
StringGrid1->Cells[i][0]=IntToStr(main_Tab[i]);
}
min_Sort(min_Tab,20);
max_Sort(max_Tab,20);
for(i=0;i<20;i++)
{
aver_Tab[i]=(1.00*max_Tab[i])/(1.00*min_Tab[i]);
StringGrid1->Cells[i][1]=IntToStr(min_Tab[i]);
StringGrid1->Cells[i][2]=IntToStr(max_Tab[i]);
StringGrid1->Cells[i][3]=FloatToStrF(aver_Tab[i],ffGeneral,2,4);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
float **tab;
fstream tab_File;
int x=StringGrid1->RowCount;
int y=StringGrid1->ColCount;
tab=new float *[x];
int i,j;
for(i=0;i<x;i++)
{
tab[i]=new float[y];
}
for(i=0;i<x;i++)
for(j=0;j<y;j++)
tab[i][j]=StrToFloat(StringGrid1->Cells[j][i]);
tab_File.open(Edit1->Text.w_str(),ios::out);
if(tab_File.good())
{
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
tab_File<<tab[i][j]<<", ";
tab_File.flush();
}
tab_File<<"\n";
}
tab_File.close();
}
for(i=0;i<x;i++)
{
delete [] tab[i];
delete [] *tab;
}
}
YOU CAN PAY ME -https://paypal.me/LukaszW77?locale.x=pl_PL
Brak komentarzy:
Prześlij komentarz