sobota, 26 sierpnia 2017
Transormations prime number and others (Visual C++)
#pragma endregion
System::Boolean is_First(int value)
{
int i,sum;
sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
System::Void init_Array(int *table, int size)
{
int i,j;
i=0;
j=2;
do
{
if(is_First(j))
{
table[i]=j;
++i;
}
++j;
}while(i<size);
}
System::Int32 sum_Table(int *table, int size)
{
int i,sum;
sum=0;
for(i=0;i<size;i++)
sum+=table[i];
return sum;
}
System::Int32 multiplication_Table(int *table, int size)
{
int i,multi;
multi=1;
for(i=0;i<size;i++)
multi*=table[i];
return multi;
}
System::Double multi_div_sum_Table(int *table, int size)
{
int i;
double value;
value=(1.*multiplication_Table(table,size))/(1.*sum_Table(table,size));
return value;
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int first_Table[9],sum_Tab[9],multi_Tab[9],not_first_Table[9],sum_not_first_Table[9],
multi_not_first_Table[9],diff_first[8],diff_not_first[8],diff_first_sum[8],diff_not_first_sum[8],
diff_first_mul[8],diff_not_first_mul[8];
double mul_dev_sum[9],mul_not_dev_sum[9],diff_mul_dev_first[8],diff_not_mul_dev[8];
int first_plus_not[9],not_plus_first[9],sum_div_first[9],sum_div_not_first[9];
double value_mal_first_div[9],value_mal_not_first_div[9];
int i,j;
init_Array(first_Table,9);
i=0;
j=1;
do
{
if(!is_First(j))
{
not_first_Table[i]=j;
++i;
}
++j;
}while(i<9);
for(i=0;i<9;i++)
{
listBox1->Items->Add(first_Table[i].ToString());
sum_Tab[i]=sum_Table(first_Table,i+1);
listBox2->Items->Add(sum_Tab[i].ToString());
multi_Tab[i]=multiplication_Table(first_Table,i+1);
listBox3->Items->Add(multi_Tab[i].ToString());
mul_dev_sum[i]=multi_div_sum_Table(first_Table,i+1);
listBox4->Items->Add(mul_dev_sum[i].ToString());
listBox5->Items->Add(not_first_Table[i].ToString());
sum_not_first_Table[i]=sum_Table(not_first_Table,i+1);
listBox6->Items->Add(sum_not_first_Table[i].ToString());
multi_not_first_Table[i]=multiplication_Table(not_first_Table,i+1);
listBox7->Items->Add(multi_not_first_Table[i].ToString());
mul_not_dev_sum[i]=multi_div_sum_Table(not_first_Table,i+1);
listBox8->Items->Add(mul_not_dev_sum[i].ToString());
}
for(i=0,j=1;i<8;i++,j++)
{
diff_first[i]=first_Table[j]-first_Table[i];
diff_not_first[i]=not_first_Table[j]-not_first_Table[i];
listBox9->Items->Add(diff_first[i].ToString());
listBox10->Items->Add(diff_not_first[i].ToString());
diff_first_sum[i]=sum_Tab[j]-sum_not_first_Table[i];
listBox11->Items->Add(diff_first_sum[i].ToString());
diff_not_first_sum[i]=sum_not_first_Table[j]-sum_Tab[i];
listBox12->Items->Add(diff_not_first_sum[i].ToString());
diff_first_mul[i]=multi_Tab[j]- multi_not_first_Table[i];
listBox13->Items->Add(diff_first_mul[i].ToString());
diff_not_first_mul[i]=multi_not_first_Table[j]-multi_Tab[i];
listBox14->Items->Add(diff_not_first_mul[i].ToString());
diff_mul_dev_first[i]=mul_dev_sum[j]-mul_not_dev_sum[i];
listBox15->Items->Add(diff_mul_dev_first[i].ToString());
diff_not_mul_dev[i]=mul_not_dev_sum[j]-=mul_dev_sum[j];
listBox16->Items->Add(diff_not_mul_dev[i].ToString());
}
first_plus_not[0]=first_Table[0];
not_plus_first[0]=not_first_Table[0];
for(i=1,j=0;i<9;i++,j++)
{
first_plus_not[i]=first_Table[i]+diff_not_first_sum[j];
not_plus_first[i]=not_first_Table[i]+diff_first_sum[j];
}
for(i=0;i<9;i++)
{
listBox17->Items->Add(first_plus_not[i].ToString());
listBox18->Items->Add(not_plus_first[i].ToString());
sum_div_first[i]=(1.*sum_Tab[i])/(1.*first_Table[i]);
listBox19->Items->Add(sum_div_first[i].ToString());
sum_div_not_first[i]=(1.*sum_not_first_Table[i])/(1.*not_first_Table[i]);
listBox20->Items->Add(sum_div_not_first[i].ToString());
value_mal_first_div[i]=(1.*multi_Tab[i])/(1.*sum_Tab[i]*first_Table[i]);
listBox21->Items->Add(value_mal_first_div[i].ToString());
value_mal_not_first_div[i]=(1.* multi_not_first_Table[i])/(1.*sum_not_first_Table[i]*not_first_Table[i]);
listBox22->Items->Add(value_mal_not_first_div[i].ToString());
}
int only_first_in_First[9],only_not_first_in_not_First[9];
for(i=0;i<9;i++)
{
only_first_in_First[i]=0;
only_not_first_in_not_First[i]=0;
}
i=0;
do
{
j=1;
do
{
if(is_First(j))
{
only_first_in_First[i]+=j;
}
++j;
}while(j<first_Table[i]);
++i;
}while(i<9);
i=0;
do
{
j=1;
do
{
if(!is_First(j))
{
only_not_first_in_not_First[i]+=j;
}
++j;
}while(j<not_first_Table[i]);
++i;
}while(i<9);
for(i=0;i<9;i++)
{
listBox23->Items->Add(only_first_in_First[i].ToString());
listBox24->Items->Add(only_not_first_in_not_First[i].ToString());
}
}
};
}
poniedziałek, 21 sierpnia 2017
File explorer C++ Builder
private: // User declarations
int size_Buf;
wchar_t *Buf;
int Bytes;
TFileStream *file;
wchar_t *Text;
wchar_t *temp_Buf;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Edit1->Text="1000";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileListBox1Click(TObject *Sender)
{
size_Buf=Edit1->GetTextLen();
Buf=new wchar_t[++size_Buf];
Edit1->GetTextBuf(Buf,size_Buf);
Bytes=_wtoi(Buf);
file=new TFileStream(FileListBox1->FileName,fmOpenRead);
temp_Buf=new wchar_t[Bytes];
file->Read(temp_Buf,Bytes);
Memo1->SetTextBuf(temp_Buf);
file->Free();
delete Buf;
delete temp_Buf;
}
Transfer Windows files via FTP
using namespace System::IO;
using namespace System::Net;
#pragma endregion
array<String^>^ files_Windows;
FtpWebRequest^ temp_req;
FileStream^ temp_file;
Stream^ temp_stream;
array<Byte>^ temp_byte;
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
files_Windows=Directory::GetFiles("c:\\Windows","*.*",System::IO::SearchOption::TopDirectoryOnly);
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
;
int i,sum_length;
sum_length=0;
listBox1->Items->Clear();
for(i=0;i<files_Windows->Length;i++)
{
listBox1->Items->Add(files_Windows[i]+" (length) "+files_Windows[i]->Length.ToString());
sum_length+=files_Windows[i]->Length;
}
label1->Text=files_Windows->Length.ToString()+" files Windows (read only)";
label2->Text="Total length: "+sum_length.ToString();
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
int i,bytes;
System::Byte size;
size=1024;
for(i=0;i<files_Windows[i]->Length;i++)
{
Uri^ location=gcnew Uri(files_Windows[i]);
temp_req=dynamic_cast<FtpWebRequest^>(WebRequest::Create(location));
temp_req->Credentials=gcnew NetworkCredential("ID_employer","IT@my_company.com");
temp_req->Method=WebRequestMethods::Ftp::UploadFile;
temp_file=gcnew FileStream(files_Windows[i],FileMode::Open);
temp_stream=temp_req->GetRequestStream();
temp_byte=gcnew array<Byte>(size);
do
{
bytes=temp_file->Read(temp_byte,0,size);
temp_stream->Write(temp_byte,0,bytes);
}while(bytes!=0);
}
temp_stream->Close();
}
};
}
czwartek, 20 lipca 2017
Lottery Visual C++
Polish Lotto game lottery draws numbers 6 out of 49. I will play 1000 bets. Numbers will be sorted and I will present the statistics.
#pragma endregion
private: int **my_Bet;
private: int *Lotto;
private: System::Void Sort(int *table, int size)
{
int i,j,temp;
for(i=1;i<size;i++)
for(j=size-1;j>=i;j--)
if(table[j]<table[j-1])
{
temp=table[j-1];
table[j-1]=table[j];
table[j]=temp;
}
}
private: System::Void init_Table()
{
int i;
my_Bet=new int*[1000];
for(i=0;i<1000;i++)
my_Bet[i]=new int[6];
Lotto=new int[6];
}
private: System::Void delete_Table()
{
int i;
for(i=0;i<1000;i++)
delete [] my_Bet[i];
delete [] *my_Bet;
delete Lotto;
}
private: System::Boolean is_Six(int *tab1, int *tab2,int size)
{
int i,j,value;
value=0;
i=0;
do
{
for(j=0;j<size;j++)
if(tab1[i]==tab2[j])
++value;
++i;
}while(i<size);
if(value==6)
return true;
else
return false;
}
private: System::Boolean is_Five(int *tab1, int *tab2,int size)
{
int i,j,value;
value=0;
i=0;
do
{
for(j=0;j<size;j++)
if(tab1[i]==tab2[j])
++value;
++i;
}while(i<size);
if(value==5)
return true;
else
return false;
}
private: System::Boolean is_Four(int *tab1, int *tab2,int size)
{
int i,j,value;
value=0;
i=0;
do
{
for(j=0;j<size;j++)
if(tab1[i]==tab2[j])
++value;
++i;
}while(i<size);
if(value==4)
return true;
else
return false;
}
private: System::Boolean is_Three(int *tab1, int *tab2,int size)
{
int i,j,value;
value=0;
i=0;
do
{
for(j=0;j<size;j++)
if(tab1[i]==tab2[j])
++value;
++i;
}while(i<size);
if(value==3)
return true;
else
return false;
}
private: System::Boolean is_Two(int *tab1, int *tab2,int size)
{
int i,j,value;
value=0;
i=0;
do
{
for(j=0;j<size;j++)
if(tab1[i]==tab2[j])
++value;
++i;
}while(i<size);
if(value==2)
return true;
else
return false;
}
private: System::Boolean is_One(int *tab1, int *tab2,int size)
{
int i,j,value;
value=0;
i=0;
do
{
for(j=0;j<size;j++)
if(tab1[i]==tab2[j])
++value;
++i;
}while(i<size);
if(value==1)
return true;
else
return false;
}
private: System::Boolean is_Zero(int *tab1, int *tab2,int size)
{
int i,j,value;
value=0;
i=0;
do
{
for(j=0;j<size;j++)
if(tab1[i]==tab2[j])
++value;
++i;
}while(i<size);
if(value==0)
return true;
else
return false;
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
srand(time(NULL));
init_Table();
dataGridView1->RowCount=1;
dataGridView1->ColumnCount=6;
dataGridView1->Rows[0]->Height=30;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
DataGridViewCellStyle^ my_Style=gcnew DataGridViewCellStyle();
System::Drawing::Font^ my_Font=gcnew
System::Drawing::Font(System::Drawing::FontFamily::GenericSansSerif,22,FontStyle::Regular);
my_Style->Font=my_Font;
dataGridView1->Rows[0]->DefaultCellStyle->BackColor=System::Drawing::Color::YellowGreen;
listBox1->Items->Clear();
int i,j,k,value;
int *temp_Lotto,**temp_Bet;
temp_Lotto=new int[49];
temp_Bet=new int*[1000];
for(i=0;i<1000;i++)
temp_Bet[i]=new int[49];
for(i=0;i<49;i++)
temp_Lotto[i]=0;
for(i=0;i<1000;i++)
for(j=0;j<49;j++)
temp_Bet[i][j]=0;
i=0;
do
{
do
{
value=rand()%49;
} while(temp_Lotto[value]!=0);
temp_Lotto[value]=1;
Lotto[i]=value+1;
++i;
}while(i<6);
i=0;
do
{
j=0;
do
{
do
{
value=rand()%49;
}while(temp_Bet[i][value]!=0);
temp_Bet[i][value]=1;
my_Bet[i][j]=value+1;
++j;
}while(j<6);
++i;
}while(i<1000);
Sort(Lotto,6);
for(i=0;i<1000;i++)
Sort(my_Bet[i],6);
for(i=0;i<6;i++)
dataGridView1->Rows[0]->Cells[i]->Value=Lotto[i].ToString();
for(i=0;i<1000;i++)
for(i=0;i<1000;i++)
{
listBox1->Items->Add((i+1).ToString()+") "+my_Bet[i][0].ToString()+","+my_Bet[i][1].ToString()+","+my_Bet[i][2].ToString()+
","+my_Bet[i][3].ToString()+","+my_Bet[i][4].ToString()+","+my_Bet[i][5].ToString());
}
int a0,a1,a2,a3,a4,a5,a6;
a0=a1=a2=a3=a4=a5=a6=0;
for(i=0;i<1000;i++)
{
if(is_Zero(my_Bet[i],Lotto,6))
++a0;
if(is_One(my_Bet[i],Lotto,6))
++a1;
if(is_Two(my_Bet[i],Lotto,6))
++a2;
if(is_Three(my_Bet[i],Lotto,6))
++a3;
if(is_Four(my_Bet[i],Lotto,6))
++a4;
if(is_Five(my_Bet[i],Lotto,6))
++a5;
if(is_Six(my_Bet[i],Lotto,6))
++a6;
}
textBox1->Text=a6.ToString();
textBox2->Text=a5.ToString();
textBox3->Text=a4.ToString();
textBox4->Text=a3.ToString();
textBox5->Text=a2.ToString();
textBox6->Text=a1.ToString();
textBox7->Text=a0.ToString();
delete [] temp_Bet[i];
delete [] *temp_Bet;
delete temp_Lotto;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
delete_Table();
Close();
}
};
}
Subskrybuj:
Posty (Atom)



