piątek, 30 grudnia 2022

PointF Visual C++

 








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);
}
};
}

sobota, 3 grudnia 2022

Mondial 2022 group C - TStringGrid - C++ Builder

 




struct mundial_2022
{
 AnsiString Name;
 int win_Goal;
 int los_Goal;
 int pkt;
}soccer_GroupC[4];;

 int __fastcall Result(int x, int y);
 void __fastcall write_Match(AnsiString team1,AnsiString team2,int goal1,int goal2,int rows);
 void __fastcall date_Team1();


__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  soccer_GroupC[0].Name="Argentina";
  soccer_GroupC[1].Name="Poland";
  soccer_GroupC[2].Name="Mexico";
  soccer_GroupC[3].Name="Saudi Arabia";
  for(int i=0;i<4;i++)
  {
   soccer_GroupC[i].win_Goal=0;
   soccer_GroupC[i].los_Goal=0;
   soccer_GroupC[i].pkt=0;
  }
}

int __fastcall TForm1::Result(int x, int y)
{
 int pkt;
 if(x>y)
  pkt=3;
 else if(x<y)
  pkt=0;
 else
  pkt=1;
 return pkt;
}
void __fastcall TForm1::write_Match(AnsiString team1,AnsiString team2,int goal1,int goal2,int rows)
{
  StringGrid1->Cells[0][rows]=team1;
  StringGrid1->Cells[1][rows]=team2;
  StringGrid1->Cells[2][rows]=IntToStr(goal1);
  StringGrid1->Cells[3][rows]=IntToStr(goal2);
}
void __fastcall TForm1::date_Team1()
{

  int goals_Arg[6]={1,2,2,0,2,0};
  int w,l;
  w=l=0;
  soccer_GroupC[0].pkt+=Result(goals_Arg[0],goals_Arg[1]);
  soccer_GroupC[0].pkt+=Result(goals_Arg[2],goals_Arg[3]);
  soccer_GroupC[0].pkt+=Result(goals_Arg[4],goals_Arg[5]);
  w=goals_Arg[0]+goals_Arg[2]+goals_Arg[4];
  l=goals_Arg[1]+goals_Arg[3]+goals_Arg[5];
  soccer_GroupC[0].win_Goal=w;
  soccer_GroupC[0].los_Goal=l;

  int goals_Pol[6]={0,0,2,0,0,2};
  w=l=0;
  soccer_GroupC[1].pkt+=Result(goals_Pol[0],goals_Pol[1]);
  soccer_GroupC[1].pkt+=Result(goals_Pol[2],goals_Pol[3]);
  soccer_GroupC[1].pkt+=Result(goals_Pol[4],goals_Pol[5]);
  w=goals_Pol[0]+goals_Pol[2]+goals_Pol[4];
  l=goals_Pol[1]+goals_Pol[3]+goals_Pol[5];
  soccer_GroupC[1].win_Goal=w;
  soccer_GroupC[1].los_Goal=l;

  int goals_Mex[6]={0,0,0,2,2,1};
  w=l=0;
  soccer_GroupC[2].pkt+=Result(goals_Mex[0],goals_Mex[1]);
  soccer_GroupC[2].pkt+=Result(goals_Mex[2],goals_Mex[3]);
  soccer_GroupC[2].pkt+=Result(goals_Mex[4],goals_Mex[5]);
  w=goals_Mex[0]+goals_Mex[2]+goals_Mex[4];
  l=goals_Mex[1]+goals_Mex[3]+goals_Mex[5];
  soccer_GroupC[2].win_Goal=w;
  soccer_GroupC[2].los_Goal=l;

  int goals_Sau[6]={2,1,0,2,1,2};
  w=l=0;
  soccer_GroupC[3].pkt+=Result(goals_Sau[0],goals_Sau[1]);
  soccer_GroupC[3].pkt+=Result(goals_Sau[2],goals_Sau[3]);
  soccer_GroupC[3].pkt+=Result(goals_Sau[4],goals_Sau[5]);
  w=goals_Sau[0]+goals_Sau[2]+goals_Sau[4];
  l=goals_Sau[1]+goals_Sau[3]+goals_Sau[5];
  soccer_GroupC[3].win_Goal=w;
  soccer_GroupC[3].los_Goal=l;


}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

 write_Match(soccer_GroupC[0].Name,soccer_GroupC[3].Name,1,2,0);
 write_Match(soccer_GroupC[1].Name,soccer_GroupC[2].Name,0,0,1);
 write_Match(soccer_GroupC[3].Name,soccer_GroupC[1].Name,0,2,2);
 write_Match(soccer_GroupC[2].Name,soccer_GroupC[0].Name,0,2,3);
 write_Match(soccer_GroupC[1].Name,soccer_GroupC[0].Name,0,2,4);
 write_Match(soccer_GroupC[2].Name,soccer_GroupC[3].Name,2,1,5);
 date_Team1();
 for(int i=0;i<4;i++)
 {
  StringGrid2->Cells[0][i]=soccer_GroupC[i].Name;
  StringGrid2->Cells[1][i]=IntToStr(soccer_GroupC[i].pkt);
  StringGrid2->Cells[2][i]=IntToStr(soccer_GroupC[i].win_Goal);
  StringGrid2->Cells[3][i]=IntToStr(soccer_GroupC[i].los_Goal);
 }
}
//---------------------------------------------------------------------------



niedziela, 27 listopada 2022

TSearchRec - C++ Builder

 


TForm1 *Form1;

SECURITY_ATTRIBUTES s_Attr={sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};


private: // User declarations
         AnsiString aFiles[4];
         TSearchRec SR;
         DWORD bytes_Size;
         char buff[1024*1024];
         HANDLE ident_File;

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  aFiles[0]="Archive";
  aFiles[1]="ReadOnly";
  aFiles[2]="Hidden";
  aFiles[3]="SysFile";
  DirectoryListBox1->FileList=FileListBox1;
  DriveComboBox1->DirList=DirectoryListBox1;
  FileListBox1->FileEdit=Edit1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileListBox1Change(TObject *Sender)
{
 AnsiString value=Edit1->Text;
 int i;
 SR.Name=value;
 SR.Attr=FileGetAttr(SR.Name);
 char* temp=FileListBox1->FileName.c_str();
 ident_File=CreateFile(temp,GENERIC_READ,FILE_SHARE_READ,&s_Attr,
 OPEN_EXISTING,0,NULL);
 if((SR.Attr & faArchive)==faArchive)
  Label2->Caption=aFiles[0];
 if((SR.Attr & faReadOnly)==faReadOnly)
  Label2->Caption=aFiles[1];
 if((SR.Attr & faHidden)==faHidden)
  Label2->Caption=aFiles[2];
 if((SR.Attr & faSysFile)==faSysFile)
  Label2->Caption=aFiles[3];
 if(ident_File!=INVALID_HANDLE_VALUE)
  ReadFile(ident_File,&buff,sizeof(buff),&bytes_Size,NULL);
 for(i=0;i<sizeof(buff)-1;i++)
  if(buff[i]==NULL)
   buff[i]='\n';
  Memo1->Text=buff;
 CloseHandle(ident_File);


}


poniedziałek, 24 października 2022

Comparison of three tickets (5/42) for 365 draws (Visual C++)


 #include "date1.h"


void m_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;

}

}


int kupon1[5] = { 1,3,29,40,42 };

int kupon2[5] = { 2,4,5,39,41 };

int kupon3[5] = {6,7,8,25,26};




bool jest_5(int* tab1, int* tab2, int s)

{

int i,j, sum;

sum = 0;

for (i = 0; i < s; i++)

{

for (j = 0; j < s; j++)

{

if (tab1[i] == tab2[j])

++sum;

}

}

if (sum == 5)

return true;

else

return false;


}

bool jest_4(int* tab1, int* tab2, int s)

{

int i, j, sum;

sum = 0;

for (i = 0; i < s; i++)

{

for (j = 0; j < s; j++)

{

if (tab1[i] == tab2[j])

++sum;

}

}

if (sum == 4)

return true;

else

return false;


}

bool jest_3(int* tab1, int* tab2, int s)

{

int i, j, sum;

sum = 0;

for (i = 0; i < s; i++)

{

for (j = 0; j < s; j++)

{

if (tab1[i] == tab2[j])

++sum;

}

}

if (sum == 3)

return true;

else

return false;


}

bool jest_2(int* tab1, int* tab2, int s)

{

int i, j, sum;

sum = 0;

for (i = 0; i < s; i++)

{

for (j = 0; j < s; j++)

{

if (tab1[i] == tab2[j])

++sum;

}

}

if (sum == 2)

return true;

else

return false;


}

bool jest_1(int* tab1, int* tab2, int s)

{

int i, j, sum;

sum = 0;

for (i = 0; i < s; i++)

{

for (j = 0; j < s; j++)

{

if (tab1[i] == tab2[j])

++sum;

}

}

if (sum == 1)

return true;

else

return false;


}

bool jest_0(int* tab1, int* tab2, int s)

{

int i, j, sum;

sum = 0;

for (i = 0; i < s; i++)

{

for (j = 0; j < s; j++)

{

if (tab1[i] == tab2[j])

++sum;

}

}

if (sum == 0)

return true;

else

return false;


}


Form1.h


private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

srand(time(NULL));

}

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {

Close();

}

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

int i, j, k;

int k1[6], k2[6], k3[6];

int temp_Tab[ilosc_Losowan][42];

int** test_Kupon;

test_Kupon = new int* [365];

for (i = 0; i < 365; i++)

test_Kupon[i] = new int[5];

for (i = 0; i < 6; i++)

{

k1[i] = 0; k2[i] = 0; k3[i] = 0;

}

for (i = 0; i < ilosc_Losowan; i++)

for (j = 0; j < 42; j++)

temp_Tab[i][j] = 0;

i = 0;

do

{

j = 0;

do

{

do

{

k = rand() % 42;

} while (temp_Tab[i][k] != 0);

temp_Tab[i][k] = 1;

test_Kupon[i][j] = k + 1;

++j;

} while (j < 5);

++i;

} while (i < ilosc_Losowan);

for (i = 0; i < ilosc_Losowan; i++)

m_Sort(test_Kupon[i], 5);

for (i = 0; i < ilosc_Losowan; i++)

{

if (jest_0(test_Kupon[i], kupon1, 5))

k1[0]++;

if (jest_0(test_Kupon[i], kupon2, 5))

k2[0]++;

if (jest_0(test_Kupon[i], kupon3, 5))

k3[0]++;

if (jest_1(test_Kupon[i], kupon1, 5))

k1[1]++;

if (jest_1(test_Kupon[i], kupon2, 5))

k2[1]++;

if (jest_1(test_Kupon[i], kupon3, 5))

k3[1]++;

if (jest_2(test_Kupon[i], kupon1, 5))

k1[2]++;

if (jest_2(test_Kupon[i], kupon2, 5))

k2[2]++;

if (jest_2(test_Kupon[i], kupon3, 5))

k3[2]++;

if (jest_3(test_Kupon[i], kupon1, 5))

k1[3]++;

if (jest_3(test_Kupon[i], kupon2, 5))

k2[3]++;

if (jest_3(test_Kupon[i], kupon3, 5))

k3[3]++;

if (jest_4(test_Kupon[i], kupon1, 5))

k1[4]++;

if (jest_4(test_Kupon[i], kupon2, 5))

k2[4]++;

if (jest_4(test_Kupon[i], kupon3, 5))

k3[4]++;

if (jest_5(test_Kupon[i], kupon1, 5))

k1[5]++;

if (jest_5(test_Kupon[i], kupon2, 5))

k2[5]++;

if (jest_5(test_Kupon[i], kupon3, 5))

k3[5]++;



}

textBox1->Text = (k1[5]).ToString();

textBox2->Text = (k1[4]).ToString();

textBox3->Text = (k1[3]).ToString();

textBox4->Text = (k1[2]).ToString();

textBox5->Text = (k1[1]).ToString();

textBox6->Text = (k1[0]).ToString();


textBox7->Text = (k2[5]).ToString();

textBox8->Text = (k2[4]).ToString();

textBox9->Text = (k2[3]).ToString();

textBox10->Text =(k2[2]).ToString();

textBox11->Text =(k2[1]).ToString();

textBox12->Text =(k2[0]).ToString();


textBox13->Text = (k3[5]).ToString();

textBox14->Text = (k3[4]).ToString();

textBox15->Text = (k3[3]).ToString();

textBox16->Text = (k3[2]).ToString();

textBox17->Text = (k3[1]).ToString();

textBox18->Text = (k3[0]).ToString();

for (i = 0; i < 365; i++)

delete[] test_Kupon[i];

delete[] test_Kupon;

}

};

}

niedziela, 25 września 2022

Reading/opening files with Windows API (C++ Builder)







 private: // User declarations

         DWORD temp_Size;

         HANDLE temp_Handle;

         bool __fastcall handle_True(HANDLE value);


TForm1 *Form1;


SECURITY_ATTRIBUTES sec_Atr={sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

        : TForm(Owner)

{


}

//---------------------------------------------------------------------------


bool __fastcall TForm1::handle_True(HANDLE value)

{

 if(value!=INVALID_HANDLE_VALUE)

  return true;

 else

  return false;

}


void __fastcall TForm1::FormCreate(TObject *Sender)

{

 DirectoryListBox1->FileList=FileListBox1;

 DriveComboBox1->DirList=DirectoryListBox1;

 FileListBox1->FileEdit=Edit1;

 Label1->Caption=DateToStr(Date())+"   "+TimeToStr(Time());


}

//---------------------------------------------------------------------------

void __fastcall TForm1::FileListBox1Change(TObject *Sender)

{

 int a;

  char buff[64*64];

 memset(buff,0,sizeof(buff)-1);

 AnsiString temp_Text=FileListBox1->FileName;

 temp_Handle=CreateFile(temp_Text.c_str(),GENERIC_READ,FILE_SHARE_READ,&sec_Atr,

 OPEN_EXISTING,0,NULL);

 if(handle_True(temp_Handle))

  ReadFile(temp_Handle,&buff,sizeof(buff),&temp_Size,NULL);

 Memo1->Text=buff;

 CloseHandle(temp_Handle);


}

poniedziałek, 19 września 2022

Connecting to Word and Excel (C++ Builder)


 

private: // User declarations


        Variant m_Excel;

        Variant m_Word;


TForm1 *Form1;


PropertySet to_Word("Visible");

PropertySet to_Excel("Visible");

Procedure close_Word("Quit");

Procedure close_Excel("Quit");


//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

        : TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)

{

 try

 {

  m_Excel=Variant::CreateObject("Excel.Application");

  to_Excel<<true;

  m_Excel.Exec(to_Excel);

 }

 catch(...)

 {

  ShowMessage("i can't open. Excel is not installed!");

 }

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

 try

 {

  m_Word=Variant::CreateObject("Word.Application");

  to_Word<<true;

  m_Word.Exec(to_Word);

 }

 catch(...)

 {

  ShowMessage("I can't open. Word is not installed!");

 }

}


//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)

{

 try

 {

  close_Excel<<false;

  m_Excel.Exec(close_Excel);

  m_Excel=Unassigned;

 }

 catch(...)

 {

  ShowMessage("Excel is not installed!");

 }

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)

{

 try

 {

  close_Word<<false;

  m_Word.Exec(close_Word);

  m_Word=Unassigned;


 }

 catch(...)

 {

  ShowMessage("Word is not installed!");

 }

}

niedziela, 11 września 2022

Voronoi shapes (C++ Builder and Lazarus)




C++ Builder 

private: // User declarations

       double __fastcall write_Distance(int a, int b, int c, int d);
       int r,g,b;
       int date_X[10], date_Y[10];

__fastcall TForm1::TForm1(TComponent* Owner)

        : TForm(Owner)

{

 srand(time(NULL));

}

double __fastcall TForm1::write_Distance(int a, int b, int c, int d)

{

 double result;

 result=sqrt((a-c)*(a-c)+(b-d)*(b-d));

 return result;

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Button1Click(TObject *Sender)

{

 TColor base_Color[10];

 int i,j,k,l,w,h;

 double d1,d2;

 j=20000+rand()%20000;

 d1=(1.00*j);

 w=PaintBox1->Width;

 h=PaintBox1->Height;

 for(i=0;i<10;i++)

 {

  r=rand()%255;

  g=rand()%255;

  b=rand()%255;

  base_Color[i]=RGB(r,g,b);

  date_X[i]=rand()%w;

  date_Y[i]=rand()%h;

 }

 for(i=0;i<w;i++)

 {

  for(j=0;j<h;j++)

  {

   d2=d1;

   for(k=0;k<10;k++)

   {

    if(write_Distance(i,j,date_X[k],date_Y[k])<d2)

    {

     l=k;

     d2=write_Distance(i,j,date_X[k],date_Y[k]);

    }

   }

   PaintBox1->Canvas->Pixels[i][j]=base_Color[l];

  }

 }

}


Lazarus


function distance_P(a,b,c,d:Integer):Real;

var

dist: real;

begin

  dist:=Sqrt((a-c)*(a-c)+(b-d)*(b-d));

  distance_P:=dist;

end;   


procedure TForm1.FormCreate(Sender: TObject);

begin

    Randomize;

end;


procedure TForm1.Button1Click(Sender: TObject);

var

  i,j,k,l,x_Width,y_Height: Integer;

  base_Colors : array[0..10] of TColor;

  x_Date : array[0..10] of Integer;

  y_Date : array[0..10] of Integer;

  temp_Distance1, temp_Distance2 : Real;

begin

  i:=20000+random(20000);

  temp_Distance1:=(1.00*i);

  base_Colors[0]:=clLime;

  base_Colors[1]:=clYellow;

  base_Colors[2]:=clRed;

  base_Colors[3]:=clGreen;

  base_Colors[4]:=clBlue;

  base_Colors[5]:=clBlack;

  base_Colors[6]:=clWhite;

  base_Colors[7]:=clAqua;

  base_Colors[8]:=clGray;

  base_Colors[9]:=clPurple;

  base_Colors[10]:=clOlive;

  x_Width:=PaintBox1.Width;

  y_Height:=PaintBox1.Height;

  for i:=0 to 10 do

  begin

   x_Date[i]:=random(x_Width);

   y_Date[i]:=random(y_Height);

  end;

  for i:=0 to x_Width do

  begin

   for j:=0 to y_Height do

   begin

       temp_Distance2:=temp_Distance1;

       for k:=0 to 10 do

       begin

           if distance_P(i,j,x_Date[k],y_Date[k])<temp_Distance2 then

           begin

             l:=k;

             temp_Distance2:=distance_P(i,j,x_Date[k],y_Date[k]);


           end;

       end;

       PaintBox1.Canvas.Pixels[i,j]:=base_Colors[l];

   end;

  end;


end;


end.

              

 

środa, 27 lipca 2022

Polish lotteries (C++ Builder)

 



__fastcall TForm1::TForm1(TComponent* Owner)

        : TForm(Owner)

{

 srand(time(NULL));

}

//---------------------------------------------------------------------------


void __fastcall TForm1::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;

 }

}



void __fastcall TForm1::Button2Click(TObject *Sender)

{

 Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

 int mini_Lotto[8][5];

 int lotto_Lotto[8][6];

 int lotto_Plus[8][6];

 int multi_Multi[8][20];

 int Kaskada[8][12];

 int i,j,k;

 int temp_Mini[8][42],temp_lotto_Lotto[8][49],temp_lotto_Plus[8][49],

 temp_multi_Multi[8][80],temp_Kaskada[8][24];


 for(i=0;i<8;i++)

  for(j=0;j<42;j++)

   temp_Mini[i][j]=0;

 for(i=0;i<8;i++)

 {

  for(j=0;j<49;j++)

  {

    temp_lotto_Lotto[i][j]=0;

    temp_lotto_Plus[i][j]=0;

  }

 }

 for(i=0;i<8;i++)

  for(j=0;j<80;j++)

   temp_multi_Multi[i][j]=0;


 for(i=0;i<8;i++)

  for(j=0;j<24;j++)

   temp_Kaskada[i][j]=0;



 //Mini Lotto 5/52


 i=0;

 do

 {

   for(j=0;j<5;j++)

   {

     do

     {

      k=rand()%42;

     }while(temp_Mini[i][k]!=0);

     temp_Mini[i][k]=1;

     mini_Lotto[i][j]=k+1;

   }

   ++i;

 }while(i<8);

 for(i=0;i<8;i++)

  iSort(mini_Lotto[i],6);

 for(i=0;i<5;i++)

  for(j=0;j<8;j++)

   StringGrid1->Cells[i][j]=IntToStr(mini_Lotto[j][i]);


//Lotto (6/49)


 i=0;

 do

 {

   for(j=0;j<6;j++)

   {

     do

     {

      k=rand()%49;

     }while(temp_lotto_Lotto[i][k]!=0);

     temp_lotto_Lotto[i][k]=1;

     lotto_Lotto[i][j]=k+1;

   }

   ++i;

 }while(i<8);

 for(i=0;i<8;i++)

  iSort(lotto_Lotto[i],6);

 for(i=0;i<6;i++)

  for(j=0;j<8;j++)

   StringGrid2->Cells[i][j]=IntToStr(lotto_Lotto[j][i]);


//Lotto Plus (6/49)


 i=0;

 do

 {

   for(j=0;j<6;j++)

   {

     do

     {

      k=rand()%49;

     }while(temp_lotto_Plus[i][k]!=0);

     temp_lotto_Plus[i][k]=1;

     lotto_Plus[i][j]=k+1;

   }

   ++i;

 }while(i<8);

 for(i=0;i<8;i++)

  iSort(lotto_Plus[i],6);

 for(i=0;i<6;i++)

  for(j=0;j<8;j++)

   StringGrid3->Cells[i][j]=IntToStr(lotto_Plus[j][i]);

//Multi Multi (20/80)


 i=0;

 do

 {

   for(j=0;j<20;j++)

   {

     do

     {

      k=rand()%80;

     }while(temp_multi_Multi[i][k]!=0);

     temp_multi_Multi[i][k]=1;

     multi_Multi[i][j]=k+1;

   }

   ++i;

 }while(i<8);

 for(i=0;i<8;i++)

  iSort(multi_Multi[i],20);

 for(i=0;i<20;i++)

  for(j=0;j<8;j++)

   StringGrid4->Cells[i][j]=IntToStr(multi_Multi[j][i]);


//Kaskada(12/24)


 i=0;

 do

 {

   for(j=0;j<12;j++)

   {

     do

     {

      k=rand()%24;

     }while(temp_Kaskada[i][k]!=0);

     temp_Kaskada[i][k]=1;

     Kaskada[i][j]=k+1;

   }

   ++i;

 }while(i<8);

 for(i=0;i<8;i++)

  iSort(Kaskada[i],12);

 for(i=0;i<12;i++)

  for(j=0;j<8;j++)

   StringGrid5->Cells[i][j]=IntToStr(Kaskada[j][i]);





}

wtorek, 7 czerwca 2022

Sum of sines (C++)

 #include <iostream>

#include <math.h>

#include <stdlib.h>

#include <time.h>


#define ss 8

using namespace std;


double y1(double b, double c)

{

return sin(b)+sin(c);

}

double y2(double b, double c)

{

double r;

r=2*sin(0.5*(b+c))*cos(0.5*(c-b));

return r;

}

double date[ss]={15.00,30.0,45.00,60.00,90.00,120.00,150.00,180.00};


double a1[ss],a2[ss];



int main(int argc, char **argv)

{

int k1,k2;

srand(time(NULL));

    for(int i=0;i<ss;i++)

    {

k1=rand()%ss;k2=rand()%ss;

a1[i]=y1(date[k1],date[k2]);

a2[i]=y2(date[k1],date[k2]);

cout<<a1[i]<<" ---- "<<a2[i]<<endl;

}


return 0;

}


sobota, 23 kwietnia 2022

Trigonometric - continue (C++)

 #include <iostream>

#include <math.h>

#include <fstream>

#define a 8


using namespace std;



double date[a]={0.00,30.00,45.00,60.00,90.00,180.00,270.00,360.00};


double f_Rad(double value)

{

return (value*3.14159265359)/180.00;

}

double msin[a],mcos[a],mtg[a],mctg[a];


int main(int argc, char **argv)

{

int i;

for(i=0;i<a;i++)

{

msin[i]=sin(f_Rad(date[i]));

mcos[i]=cos(f_Rad(date[i]));

mtg[i]=msin[i]/mcos[i];

mctg[i]=1.00/mtg[i];

}

fstream file("table.txt",ios::out);

if(file.good())

{

file<<"sin: 0,30,45,60,90,180,270,360\n";

for(i=0;i<a;i++)

{

file<<msin[i]<<"  ";

}

file<<"\n";

file<<"cos: 0,30,45,60,90,180,270,360\n";

for(i=0;i<a;i++)

{

file<<mcos[i]<<"  ";

}

file<<"\n";

file<<"tg: 0,30,45,60,90,180,270,360\n";

for(i=0;i<a;i++)

{

file<<mtg[i]<<"  ";

}

file<<"\n";

file<<"ctg: 0,30,45,60,90,180,270,360\n";

for(i=0;i<a;i++)

{

file<<mctg[i]<<"  ";

}

file<<"\n";

file.close();

}

return 0;

}


czwartek, 21 kwietnia 2022

Trigonometrict function (C++ Builder)

 


void __fastcall TForm1::TrackBar1Change(TObject *Sender)

{

 int x;

 double y,y1;

 x=TrackBar1->Position;

 Label1->Caption=IntToStr(x);

 y=(1.00*x);

 y1=y*(M_PI/180.00);

 Label2->Caption="sin: "+FloatToStrF(sin(y),ffGeneral,2,2);

 Label3->Caption="cos: "+FloatToStrF(cos(y),ffGeneral,2,2);

 Label4->Caption="tg: "+FloatToStrF(sin(y)/cos(y),ffGeneral,2,2);

 Label5->Caption="ctg:"+FloatToStrF(1.00/(sin(y)/cos(y)),ffGeneral,2,2);

 Label6->Caption="sin: (rad)  "+FloatToStrF(sin(y1),ffGeneral,2,2);

 Label7->Caption="cos: (rad)  "+FloatToStrF(cos(y1),ffGeneral,2,2);

 Label8->Caption="tg:  (rad)  "+FloatToStrF(sin(y1)/cos(y1),ffGeneral,2,2);

 Label9->Caption="ctg: (rad)  "+FloatToStrF(1.00/(sin(y1)/cos(y1)),ffGeneral,2,2);



}