czwartek, 29 listopada 2018

Use of arrays and conversion of pixels - Visual C++


#pragma endregion
private:
System::Boolean is_First(System::Int64 value)
{
System::Int64 i;
System::Int64 sum;
sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
private:
array<System::Boolean,2>^ tab_Bool;
private:
array<System::Int64,2>^ tab_Single;
private:
array<System::Int64>^ tab_First;
System::Void init_Arrays()
{
System::Int64 i;
System::Int64 j;
System::Int64 k;
tab_Bool=gcnew array<System::Boolean,2>(200,200);
tab_Single=gcnew array<System::Int64,2>(200,200);
tab_First=gcnew array<System::Int64>(200*200);
for(i=0;i<200*200;i++)
tab_First[i]=i+1;
k=0;
for(i=0;i<200;i++)
{
for(j=0;j<200;j++)
{
tab_Single[i,j]=tab_First[k];
++k;
}
}
for(i=0;i<200;i++)
{
for(j=0;j<200;j++)
{
                  k=tab_Single[i,j]; 
 if(is_First(k))
 {
 tab_Bool[i,j]=true;
 }
 else
 {
 tab_Bool[i,j]=false;
 }
}
}
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

System::Int64 i;
System::Int64 j;
Graphics^ graph_Panel=panel1->CreateGraphics();
Graphics^ graph_Panel2=panel2->CreateGraphics();
Graphics^ graph_Panel3=panel3->CreateGraphics();
Bitmap^ map_Panel=gcnew Bitmap(panel1->Width,panel1->Height);
Bitmap^ map_Panel2=gcnew Bitmap(panel2->Width,panel2->Height);
Bitmap^ map_Panel3=gcnew Bitmap(panel3->Width,panel3->Height);
Graphics^ graph_Panel4=panel4->CreateGraphics();
Graphics^ graph_Panel5=panel5->CreateGraphics();
Graphics^ graph_Panel6=panel6->CreateGraphics();
Bitmap^ map_Panel4=gcnew Bitmap(panel4->Width,panel1->Height);
Bitmap^ map_Panel5=gcnew Bitmap(panel5->Width,panel2->Height);
Bitmap^ map_Panel6=gcnew Bitmap(panel6->Width,panel3->Height);
System::Drawing::Color color1;
System::Drawing::Color color2;
System::Drawing::Color color3;
System::Drawing::Color color4;
System::Drawing::Color color5;
System::Drawing::Color color6;
color1=System::Drawing::Color::Green;
color2=System::Drawing::Color::Yellow;
color3=System::Drawing::Color::White;
color4=System::Drawing::Color::Black;
color5=System::Drawing::Color::Red;
color6=System::Drawing::Color::Blue;

init_Arrays();

for(i=0;i<200;i++)
{
for(j=0;j<200;j++)
{
if(tab_Bool[i,j])
{
map_Panel->SetPixel(i,j,color2);
map_Panel2->SetPixel(i,j,color4);
map_Panel3->SetPixel(i,j,color6);
map_Panel4->SetPixel(j,i,color1);
map_Panel5->SetPixel(j,i,color3);
map_Panel6->SetPixel(j,i,color5);
}
else
{
map_Panel->SetPixel(i,j,color1);
map_Panel2->SetPixel(i,j,color3);
map_Panel3->SetPixel(i,j,color5);
map_Panel4->SetPixel(j,i,color2);
map_Panel5->SetPixel(j,i,color4);
map_Panel6->SetPixel(j,i,color6);
}
}
}
graph_Panel->DrawImage(dynamic_cast<Image^>(map_Panel),10,10);
graph_Panel2->DrawImage(dynamic_cast<Image^>(map_Panel2),10,10);
graph_Panel3->DrawImage(dynamic_cast<Image^>(map_Panel3),10,10);
graph_Panel4->DrawImage(dynamic_cast<Image^>(map_Panel4),10,10);
graph_Panel5->DrawImage(dynamic_cast<Image^>(map_Panel5),10,10);
graph_Panel6->DrawImage(dynamic_cast<Image^>(map_Panel6),10,10);

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


piątek, 23 listopada 2018

Aliphinic transformations in Visual C ++.



Project is compiled. Unfoftunately, the coordinates got out of control. Drawing is impossible alhought the idea and code correct. Maybe someone can improve it. I did not succeed. 

struct Date
{
double X1[4];
double X2[4];
double X3[4];
double X4[4];
double X5[4];
double X6[4];
double a,b;
};
#pragma endregion
System::Double is_Minus()
{
int x;
x=rand()%20;
if(x>=14)
return -1.00;
else
return 1.00;
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
struct Date *date_Image=new struct Date[5];
int i,j,k;
 for(i=0;i<5;i++)
 {
for(j=0;j<4;j++)
{
date_Image[i].X1[j]=rand()%100/90*0.33;
date_Image[i].X2[j]=rand()%210/80*0.90;
date_Image[i].X3[j]=rand()%100/95*0.33;
date_Image[i].X4[j]=0.0;
date_Image[i].X5[j]=rand()%300/200*0.22;
 
 

}
}
  for(i=0;i<5;i++)
  {
for(j=0;j<4;j++)
{
date_Image[i].X1[j]*=is_Minus();
date_Image[i].X2[j]*=is_Minus();
date_Image[i].X3[j]*=is_Minus();
date_Image[i].X4[j]=0.0;
date_Image[i].X5[j]*=is_Minus();
 
}
  }
Graphics^ s1=panel1->CreateGraphics();
Graphics^ s2=panel2->CreateGraphics();
Graphics^ s3=panel3->CreateGraphics();
Graphics^ s4=panel4->CreateGraphics();
Graphics^ s5=panel5->CreateGraphics();
System::Drawing::Color c1;
System::Drawing::Color c2;
System::Drawing::Color c3;
System::Drawing::Color c4;
System::Drawing::Color c5;
Bitmap^ b1=gcnew Bitmap(panel1->Width,panel1->Height);
Bitmap^ b2=gcnew Bitmap(panel2->Width,panel2->Height);
Bitmap^ b3=gcnew Bitmap(panel3->Width,panel3->Height);
Bitmap^ b4=gcnew Bitmap(panel4->Width,panel4->Height);
Bitmap^ b5=gcnew Bitmap(panel5->Width,panel5->Height);
for(i=0;i<5;i++)
{
date_Image[i].a=rand()%2000;
date_Image[i].b=rand()%2000;
}

 
for(i=0;i<10000;i++)
{
for(j=0;j<5;j++)
{
k=rand()%4;
switch(k)
{
case 0:
date_Image[j].a=date_Image[j].a*date_Image[j].X1[0]+date_Image[j].b*date_Image[j].X2[0]+date_Image[j].X3[0];
date_Image[j].b=date_Image[j].a*date_Image[j].X4[0]+date_Image[j].b*date_Image[j].X5[0]+date_Image[j].X6[0];
break;

case 1:
date_Image[j].a=date_Image[j].a*date_Image[j].X1[1]+date_Image[j].b*date_Image[j].X2[1]+date_Image[j].X3[1];
date_Image[j].b=date_Image[j].a*date_Image[j].X4[1]+date_Image[j].b*date_Image[j].X5[1]+date_Image[j].X6[1];
break;
case 2:
date_Image[j].a=date_Image[j].a*date_Image[j].X1[2]+date_Image[j].b*date_Image[j].X2[2]+date_Image[j].X3[2];
date_Image[j].b=date_Image[j].a*date_Image[j].X4[2]+date_Image[j].b*date_Image[j].X5[2]+date_Image[j].X6[2];
break;
case 3:
date_Image[j].a=date_Image[j].a*date_Image[j].X1[3]+date_Image[j].b*date_Image[j].X2[3]+date_Image[j].X3[3];
date_Image[j].b=date_Image[j].a*date_Image[j].X4[3]+date_Image[j].b*date_Image[j].X5[3]+date_Image[j].X6[3];
break;

}
c1=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
c2=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
c3=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
c4=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
c5=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
b1->SetPixel(panel1->Width/10+floor(10*date_Image[0].a),panel1->Height-10+floor(10*date_Image[0].b),c1);
                        b2->SetPixel(panel2->Width/10+floor(10*date_Image[1].a),panel2->Height-10+floor(10*date_Image[1].b),c2);
b3->SetPixel(panel3->Width/10+floor(10*date_Image[2].a),panel3->Height-10+floor(10*date_Image[2].b),c3);
b4->SetPixel(panel4->Width/10+floor(10*date_Image[3].a),panel4->Height-10+floor(10*date_Image[3].b),c4);
b5->SetPixel(panel5->Width/10+floor(10*date_Image[4].a),panel5->Height-10+floor(10*date_Image[4].b),c5);

}
}
s1->DrawImage(dynamic_cast<Image^>(b1),10,10);
s2->DrawImage(dynamic_cast<Image^>(b2),10,10);
s3->DrawImage(dynamic_cast<Image^>(b3),10,10);
s4->DrawImage(dynamic_cast<Image^>(b4),10,10);
s5->DrawImage(dynamic_cast<Image^>(b5),10,10);
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
srand(time(NULL));
}
};
}




czwartek, 22 listopada 2018

String Grids and transformation - C++ Builder



private: // User declarations
        bool __fastcall is_First(int value);
        int main_Array[10][10];
        int temp_Array[100];
        int total_Vertical[10],total_Horizontal[10],difference_Vertical[10],
        difference_Horizontal[10];
        int A,B,C,D;
        void __fastcall init_Array();


bool __fastcall TForm1::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;
}
void __fastcall TForm1::init_Array()
{
 int i,j,k,sum,difference;
 i=0;
 j=2;
 do
 {
  if(is_First(j))
  {
   temp_Array[i]=j;
   ++i;
  }
  ++j;
 }while(i<100);
 k=0;
 for(i=0;i<10;i++)
 {
  for(j=0;j<10;j++)
  {
   main_Array[i][j]=temp_Array[k];
   ++k;
  }

 }
 i=0;
 do
 {
  sum=0,k=9,difference=main_Array[i][k];
  for(j=0;j<10;j++)
  {
   sum+=main_Array[i][j];
   difference-=main_Array[i][k-j];
   }
  total_Vertical[i]=sum;
  difference_Vertical[i]=difference;
  ++i;

 }while(i<10);

i=0;
do
{
 sum=0,k=9,difference=main_Array[k][i];
 for(j=0;j<10;j++)
 {
  sum+=main_Array[j][i];
  difference-=main_Array[k-j][i];
 }
 total_Horizontal[i]=sum;
 difference_Horizontal[i]=difference;
 ++i;
}while(i<10);
A=B=0;
C=main_Array[9][9];
D=main_Array[0][9];
for(i=0;i<10;i++)
{
 A+=main_Array[i][i];
 B+=main_Array[i][9-i];
 C-=main_Array[9-i][9-i];
 D-=main_Array[i][9-i];

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

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 int i,j;
 for(i=0;i<10;i++)
 {
  for(j=0;j<10;j++)
  {
   StringGrid1->Cells[i][j]=IntToStr(main_Array[j][i]);
  }
 }
 for(i=0;i<10;i++)
 {
  StringGrid5->Cells[0][i]=IntToStr(total_Vertical[i]);
  StringGrid4->Cells[0][i]=IntToStr(difference_Vertical[i]);

  StringGrid2->Cells[i][0]=IntToStr(total_Horizontal[i]);
  StringGrid3->Cells[i][0]=IntToStr(difference_Horizontal[i]);
 }
 StringGrid9->Cells[0][0]=IntToStr(A);
 StringGrid7->Cells[0][0]=IntToStr(B);
 StringGrid6->Cells[0][0]=IntToStr(C);
 StringGrid8->Cells[0][0]=IntToStr(D);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
 Close();
}

niedziela, 11 listopada 2018

The queue and data about the exe file (C++ Builder)



template <class temp_Value> class t_Queue
{
 private:
int start,end,max_Value;
temp_Value *class_Value;
 public:
   t_Queue(int i)
   {
  start=0;
  end=0;
  max_Value=i;
  class_Value=new temp_Value[max_Value+1];
   }

   bool is_Empty()
   {
  bool b_value;
  if(start==end)
b_value=true;
  else
b_value=false;
  return b_value;

   }
   bool make_Op(temp_Value &make_Value)
   {
  if(start==end)
return false;
  make_Value=class_Value[start++];
  if(start>max_Value)
start=0;
  return true;
   }
   void insert_Q(temp_Value i)
   {
  class_Value[end++]=i;
  if(end>max_Value)
        end=0;
   }
};

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 int i;
 bool j;
 UnicodeString info_Exe[5];
 UnicodeString info_Text[5];
 UnicodeString temp_Name;
 UnicodeString text_Value;

 temp_Name=Application->ExeName;
 info_Exe[0]=ExtractFileName(temp_Name);
 info_Exe[1]=ExtractFileDir(temp_Name);
 info_Exe[2]=ExtractFileDrive(temp_Name);
 info_Exe[3]=ExtractFileExt(temp_Name);
 info_Exe[4]=ExtractRelativePath(GetCurrentDir(),temp_Name);
 info_Text[0]="File Name: ";
 info_Text[1]="Directory: ";
 info_Text[2]="Drive: ";
 info_Text[3]="Extension File: ";
 info_Text[4]="Path: ";
 t_Queue<UnicodeString> text_Queue(5),info_Queue(5);
 for(i=0;i<5;i++)
 {
text_Queue.insert_Q(info_Text[i]);
info_Queue.insert_Q(info_Exe[i]);
 }
 for(i=0;i<6;i++)
 {
   j=text_Queue.make_Op(temp_Name);
   if(j)
ListBox1->Items->Add(temp_Name);
   else
ListBox1->Items->Add("Queue is empty!");
 }
 for(i=0;i<6;i++)
 {
   j=info_Queue.make_Op(temp_Name);
   if(j)
ListBox2->Items->Add(temp_Name);
   else
    ListBox2->Items->Add("Queue is empty!");
 }
}

środa, 7 listopada 2018

Class that check file (g++ Linux)

 vim f_access.cxx

#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
using namespace std;

class FILE_ACCESS
{
    private:
    struct stat st_file;
    char *file_name;
    int read_value;
    int write_value;
    int exist_value;
    bool is_True(int x);
    public:
    FILE_ACCESS(char *f_name);
    void Report1();
    void Report2();
};
bool FILE_ACCESS::is_True(int x)
{
    if(x==0)
     return true;
    else
     return false;
}
FILE_ACCESS::FILE_ACCESS(char *f_name)
{
    file_name=f_name;
    lstat(file_name,&st_file);
   
}
void FILE_ACCESS::Report1()
{
    exist_value=access(file_name,F_OK);
    if(is_True(exist_value))
    {
     cout<<file_name<<"  exists "<<endl;
    }
    else
    {
        if(errno==ENOENT)
        {
            cout<<file_name<<"  not exists "<<endl;
           
        }
        else if(errno==EACCES)
        {
            cout<<file_name<<"  is unavailable "<<endl;
           
        }
    }
    read_value=access(file_name,R_OK);
    if(is_True(read_value))
    {
        cout<<file_name<<" is readable "<<endl;
        cout<<"process "<< (int)getpid<<endl;
    }
    else
    {
        cout<<file_name<<" is not readable "<<endl;
    }
    write_value=access(file_name,W_OK);
    if(is_True(write_value))
    {
        cout<<file_name<<" is writetable "<<endl;
    }
    else if(errno==EACCES)
    {
        cout<<file_name<<" is not writetable  (access denied)"<<endl;
    }
    else if(errno==EROFS)
    {
        cout<<file_name<<" is not writetable (only read-only)"<<endl;
    }
}
    void FILE_ACCESS::Report2()
    {
        if(S_ISLNK(st_file.st_mode))
        {
            cout<<" symbolic link "<<endl;
        }
        else if(S_ISDIR(st_file.st_mode))
        {
            cout<<" directory "<<endl;
        }
        else if(S_ISCHR(st_file.st_mode))
        {
            cout<<" character device "<<endl;
        }
        else if(S_ISBLK(st_file.st_mode))
        {
            cout<<" block device "<<endl;
        }
        else if(S_ISFIFO(st_file.st_mode))
        {
            cout<<" FIFO queue "<<endl;
        }
        else if(S_ISSOCK(st_file.st_mode))
        {
            cout <<" socket "<<endl;
        }
        else if(S_ISREG(st_file.st_mode))
        {
            cout<<" plain file"<<endl;
        }
       
    }
   
   

int main(int argc, char **argv)
{
    FILE_ACCESS my_ACCESS1("/bin/bash"),my_ACCESS2("f_access.cxx");
    my_ACCESS1.Report1();
    my_ACCESS1.Report2();
    my_ACCESS2.Report1();
    my_ACCESS2.Report2();
   
   
   
   
    return 0;
}

poniedziałek, 5 listopada 2018

Reading data from a file (C++)


I want to find out what happened at the given time in the system.
Windows stores error reports in the file - PFRO.


Functions for char and wchar_t types:

wchar_t* __fastcall TForm1::PFRO_Report() { wchar_t end='\0'; wchar_t *report; wchar_t *reply; wchar_t temp_buff[2048]; wchar_t *incident=L"3/18/2017 18:27:22 - PFRO Error:"; size_t byt_read_values; FILE *file; file=_wfopen(L"c:\Windows\PFRO.log",L"r+"); byt_read_values=fread(temp_buff,1,sizeof(temp_buff),file); fclose(file); temp_buff[byt_read_values]=end; report=wcsstr(temp_buff,incident); if(report==0) return 0; swscanf(report,incident,L"%s",reply); return reply; }

char* __fastcall TForm1::PFRO_Report() { char end='\0'; char *report; char *reply; char temp_buff[2048]; char *incident="3/18/2017 18:27:22 - PFRO Error:"; size_t byt_read_values; FILE *file; file=fopen("c:\Windows\PFRO.log","r"); byt_read_values=fread(temp_buff,1,sizeof(temp_buff),file); fclose(file); temp_buff[byt_read_values]=end; report=strstr(temp_buff,incident); if(report==0) return 0; sscanf(report,incident,L"%s",reply); return reply; }