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;

}