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

}
};
}