środa, 18 stycznia 2017

Writing binary data to a file



private: // User declarations
int delta,a,b,c;
float x1,x2;
int more_Delta[20][3];
int less_Delta[20][3];
int is_Delta[20][3];
void __fastcall init_Random();
int __fastcall is_Minus(int value);

#define min 1
#define max_value 10
#define max 20
TForm6 *Form6;
//---------------------------------------------------------------------------
__fastcall TForm6::TForm6(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
 void __fastcall TForm6::init_Random()
 {
srand(time(NULL));
 }
 int __fastcall TForm6::is_Minus(int value)
 {
int x;
x=rand()%2;
if(x==0)
 value*=-1;
return value;
 }
void __fastcall TForm6::FormCreate(TObject *Sender)
{
 init_Random();
 int i,sum,j;

 i=0;
 do
 {
  do{
   a=rand()%max_value+min;
   b=rand()%max_value+min;
   c=rand()%max_value+min;
   a=is_Minus(a);
   b=is_Minus(b);
   c=is_Minus(c);
   delta=(b*b)-(4*a*c);
   }while(delta<0);
   more_Delta[i][0]=a;
   more_Delta[i][1]=b;
   more_Delta[i][2]=c;
   i++;
 }while(i<max);
 i=0;
 do
 {
  do{
   a=rand()%max_value+min;
   b=rand()%max_value+min;
   c=rand()%max_value+min;
   a=is_Minus(a);
   b=is_Minus(b);
   c=is_Minus(c);
   delta=(b*b)-(4*a*c);
   }while(delta>0);
   less_Delta[i][0]=a;
   less_Delta[i][1]=b;
   less_Delta[i][2]=c;
   i++;
 }while(i<max);
 i=0;
 do
 {
  do{
   a=rand()%max_value+min;
   b=rand()%max_value+min;
   c=rand()%max_value+min;
   a=is_Minus(a);
   b=is_Minus(b);
   c=is_Minus(c);
   delta=(b*b)-(4*a*c);
   }while(delta!=0);
   is_Delta[i][0]=a;
   is_Delta[i][1]=b;
   is_Delta[i][2]=c;
   i++;
 }while(i<max);
 for(i=0;i<max;i++)
 {
StringGrid1->Cells[0][i]=IntToStr(more_Delta[i][0]);
StringGrid1->Cells[1][i]=IntToStr(more_Delta[i][1]);
StringGrid1->Cells[2][i]=IntToStr(more_Delta[i][2]);
StringGrid2->Cells[0][i]=IntToStr(less_Delta[i][0]);
StringGrid2->Cells[1][i]=IntToStr(less_Delta[i][1]);
StringGrid2->Cells[2][i]=IntToStr(less_Delta[i][2]);
StringGrid3->Cells[0][i]=IntToStr(is_Delta[i][0]);
StringGrid3->Cells[1][i]=IntToStr(is_Delta[i][1]);
StringGrid3->Cells[2][i]=IntToStr(is_Delta[i][2]);
 }
}
//---------------------------------------------------------------------------

void __fastcall TForm6::Button2Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm6::Button1Click(TObject *Sender)
{
 FILE *my_file;
 int i;
 my_file=fopen("equal.txt","w");
 fprintf(my_file,"%s","delta>0");
 fprintf(my_file,"\n");
 for(i=0;i<max;i++)
 {
fprintf(my_file,"%d ",more_Delta[i][0]);
fprintf(my_file,"%d ",more_Delta[i][1]);
fprintf(my_file,"%d ",more_Delta[i][2]);
fprintf(my_file,"\n");
 }
 fprintf(my_file,"%s","delta<0");
 fprintf(my_file,"\n");
 for(i=0;i<max;i++)
 {
fprintf(my_file,"%d ",less_Delta[i][0]);
fprintf(my_file,"%d ",less_Delta[i][1]);
fprintf(my_file,"%d ",less_Delta[i][2]);
fprintf(my_file,"\n");
 }
 fprintf(my_file,"%s","delta=0");
 fprintf(my_file,"\n");
 for(i=0;i<max;i++)
 {
fprintf(my_file,"%d ",is_Delta[i][0]);
fprintf(my_file,"%d ",is_Delta[i][1]);
fprintf(my_file,"%d ",is_Delta[i][2]);
fprintf(my_file,"\n");
 }
 fclose(my_file);
}

Result:


Brak komentarzy:

Prześlij komentarz