niedziela, 16 października 2016

Testing C++ Builder 10.1 Berlin Starter

I was downloading C++ Builder 10.1 Berlin Starter, before was used C++ Builder 6 Personal.



void __fastcall TForm4::Frame()
{
int margin=5;
int width=PaintBox1->Width-margin;
int height=PaintBox1->Height-margin;
PaintBox1->Canvas->Pen->Color=clGreen;
PaintBox1->Canvas->MoveTo(margin,margin);
PaintBox1->Canvas->LineTo(width,margin);
PaintBox1->Canvas->LineTo(width,height);
PaintBox1->Canvas->LineTo(margin,height);
PaintBox1->Canvas->LineTo(margin,margin);
}
void __fastcall TForm4::Diagonals()
{
int margin=5;
int width=PaintBox1->Width-margin;
int height=PaintBox1->Height-margin;
PaintBox1->Canvas->MoveTo(margin,margin);
PaintBox1->Canvas->LineTo(width,height);
PaintBox1->Canvas->MoveTo(width,margin);
PaintBox1->Canvas->LineTo(margin,height);
}
void __fastcall TForm4::Cross()
{
  int margin=5;
  int width=PaintBox1->Width-margin;
  int height=PaintBox1->Height-margin;
  int my_width=width/2;
  int my_height=height/2;
  PaintBox1->Canvas->Pen->Color=clRed;
  PaintBox1->Canvas->MoveTo(margin,my_height);
  PaintBox1->Canvas->LineTo(width,my_height);
  PaintBox1->Canvas->MoveTo(my_width,margin);
  PaintBox1->Canvas->LineTo(my_width,height);

}
void __fastcall TForm4::Circles()
{
int centrum_x=PaintBox1->Width/2;
int centrum_y=PaintBox1->Height/2;
int value=30;
PaintBox1->Canvas->Ellipse(centrum_x,centrum_y,value,value);
PaintBox1->Canvas->Ellipse(centrum_x,centrum_y,2*centrum_x-value,2*centrum_y-value);

}
void __fastcall TForm4::Rectangles()
{
  int centrum_x=PaintBox1->Width/2;
  int centrum_y=PaintBox1->Height/2;
  int value=60;
  PaintBox1->Canvas->Brush->Color=clYellow;
  PaintBox1->Canvas->Rectangle(value,centrum_y,centrum_x-value,2*centrum_y-value);
  PaintBox1->Canvas->Rectangle(centrum_x+value,value,2*centrum_x-value,centrum_y);
}

void __fastcall TForm4::Text()
{
int value=40;
int x_north=PaintBox1->Width/2;
int y_north=value;
int x_east=PaintBox1->Width-value;
int y_east=PaintBox1->Height/2;
int x_south=PaintBox1->Width/2;
int y_south=PaintBox1->Height-value;
int x_west=value;
int y_west=PaintBox1->Height/2;
PaintBox1->Canvas->Brush->Color=clWhite;
PaintBox1->Canvas->TextOutW(x_north,y_north,"North");
PaintBox1->Canvas->TextOutW(x_east,y_east,"East");
PaintBox1->Canvas->TextOutW(x_south,y_south,"South");
PaintBox1->Canvas->TextOutW(x_west,y_west,"West");

}
void __fastcall TForm4::Button1Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm4::Button2Click(TObject *Sender)
{
 Frame();
 Diagonals();
 Cross();
 Circles();
 Rectangles();
 Text();

}
//---------------------------------------------------------------------------


poniedziałek, 3 października 2016

Create new files with new names and writes in Visual C++


Result:

private: System::Void init_Random()
{
srand(time(NULL));
}
private: System::Char my_Lowercase()
{
int x,j=1;;
char i;
x=rand()%26;
i='a';
for(j=0;j<=x-1;j++)
{
i++;
}

return i;

}
private: System::Char my_Uppercase()
{
int x,j=1;
char i;
i='A';
x=rand()%26;
for(j=0;j<=x-1;j++)
{
i++;
}

return i;

}
private: System::Char case_ListBox()
 {
 int i;
 i=rand()%2;
 if(i==1)
 return my_Uppercase();
 else
 return my_Lowercase();
 }
 private: System::Int16 my_Number()
  {
  int x;
  x=rand()%10;
  return x;
  }
private: System::String^ symbol_ListBox()
 {
 int i;
 i=rand()%2;
 if(i==1)
 return case_ListBox().ToString();
 else
 return my_Number().ToString();
 }
private: System::Void clear_ListBoxes()
 {
               listBox1->Items->Clear();
  listBox2->Items->Clear();
  listBox3->Items->Clear();
  listBox4->Items->Clear();
  listBox5->Items->Clear();

 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
 
init_Random();
timer1->Start();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
int i;
int j,how_many;
 
how_many=Convert::ToInt16(textBox1->Text);
array <System::String^>^ my_string=gcnew array<System::String^>(how_many);
clear_ListBoxes();
for(i=0;i<how_many;i++)
{
listBox1->Items->Add(case_ListBox().ToString());
listBox2->Items->Add(symbol_ListBox());
listBox3->Items->Add(case_ListBox().ToString());
listBox4->Items->Add(symbol_ListBox());
my_string[i]=listBox1->Items[i]->ToString()+listBox2->Items[i]->ToString()+listBox3->Items[i]->ToString()+listBox4->Items[i]->ToString()+".txt";
listBox5->Items->Add(my_string[i]);
}
i=0;
do
{
 StreamWriter^ my_stream = gcnew StreamWriter(my_string[i]);
 my_stream->Write(label7->Text);
     my_stream->Close();
 i++;
}while(i<how_many);

}
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
DateTime my_time=DateTime::Now;
label7->Text="  time "+my_time.Hour.ToString("D2")+":"+my_time.Minute.ToString("D2")+":"+my_time.Second.ToString()+
" date "+my_time.Day.ToString()+"-"+my_time.Month.ToString()+"-"+my_time.Year.ToString();
}
private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
timer1->Stop();
}
};



}




wtorek, 27 września 2016

First numbers in dataGridView (Visual C++)



#pragma endregion
#define a 10
#define b 40
#define c 100
int *tab_first;
int *between_value,*between_value2;
int *rows_value;

private: System::Boolean  first_Number(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+a;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}

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

tab_first=new int[c];
between_value=new int[c];
rows_value=new int[c];
between_value2=new int[c];
dataGridView1->ColumnCount=a;
dataGridView1->RowCount=a;
dataGridView2->ColumnCount=a;
dataGridView2->RowCount=a;
dataGridView3->ColumnCount=a;
dataGridView3->RowCount=a;
dataGridView4->ColumnCount=a;
dataGridView4->RowCount=a;
int i,j,k,sum;
for(i=0;i<a;i++)
{
dataGridView1->Columns[i]->Width=b;
dataGridView1->Rows[i]->Height=b/2;
dataGridView2->Columns[i]->Width=b;
dataGridView2->Rows[i]->Height=b/2;
dataGridView3->Columns[i]->Width=b;
dataGridView3->Rows[i]->Height=b/2;
dataGridView4->Columns[i]->Width=b;
dataGridView4->Rows[i]->Height=b/2;

}
i=0;
j=1;
do
{
if(first_Number(j))
{
                       tab_first[i]=j;
  ++i;
}
++j;

}while(i<c);
 
 
i=0;
do
{
j=tab_first[i];
sum=0;
do
{
                   ++sum;
  

}while(j+sum<tab_first[i+1]);
between_value[i]=sum;
               ++i;
 
}while(i<c);

}
 
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
delete between_value2;
delete rows_value;
delete between_value;
delete tab_first;
Close();
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
int i,j,k,temp_table[a][a],temp_table2[a][a];
k=0;
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
dataGridView1->Rows[i]->Cells[j]->Value=tab_first[k].ToString();
dataGridView2->Rows[i]->Cells[j]->Value=between_value[k].ToString();
temp_table[i][j]=tab_first[k];
++k;
}
}
             k=0;
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
temp_table2[i][j]=temp_table[j][i];
dataGridView3->Rows[i]->Cells[j]->Value=temp_table2[i][j].ToString();
rows_value[k]=temp_table2[i][j];
}
}
System::Int32 x;
System::Int32 y;
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
x=Int32::Parse(dataGridView1->Rows[i]->Cells[j]->Value->ToString());
y=Int16::Parse(dataGridView3->Rows[i]->Cells[j]->Value->ToString());
if(x==y)
dataGridView4->Rows[i]->Cells[j]->Value="1";
else
dataGridView4->Rows[i]->Cells[j]->Value="0";
}
}
int *table_value1,*table_value2;
table_value1=new int[a];
table_value2=new int[a];
            for(i=0;i<a;i++)
{
for(k=0;k<a;k++)
{
if(i==k)
{
table_value1[i]=Int32::Parse(dataGridView1->Rows[i]->Cells[k]->Value->ToString());
table_value2[i]=Int32::Parse(dataGridView2->Rows[i]->Cells[k]->Value->ToString());
listBox1->Items->Add((i+1).ToString()+") "+table_value1[i].ToString()+"-----"+table_value2[i].ToString());
}
}
}
    

delete table_value2;
delete table_value1;

 
 
 
 




 


}
};
}

piątek, 23 września 2016

Relations on first numbers in Visaul C++



#pragma endregion
private: System::Void init_Random()
{
srand(time(NULL));
}
private: System::Boolean is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
private: System::Void write_Table(int *table, int size)
 {
                int i,j;
i=0;j=1;
do
{
if(is_First(j))
{
table[i]=j;
++i;
}
++j;
}while(i<size+1);
 }
 private: System::Int32 howmany_Elements(int x)
  {
  int i,sum;
  i=1,sum=1;
  do
  {
  
  if(is_First(i))
  {
  ++sum;
  
  }
  ++i;

  }while(i!=x);
  return sum;

  }
 private: System::Int32 sum_Table(int *table, int size)
  {
  int i,sum;
  sum=0;
  for(i=0;i<size;i++)
  sum+=table[i];
      return sum;
  }
  private: System::Int32 random_First()
{
int x,i,max;
max=1000;
x=rand()%max+2;
if(!is_First(x))
{   i=x;
do
{
++i;
}while(!is_First(i));
return i;
}
else
return x;
}
  private: int *table;
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) { 
Close();
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
int x,how_many_in_table,sum,i;
x=random_First();
textBox1->Text=x.ToString();
how_many_in_table=howmany_Elements(x);
textBox2->Text=how_many_in_table.ToString();
table=new int[how_many_in_table];
listBox1->Items->Clear();
write_Table(table,how_many_in_table);
sum=sum_Table(table,how_many_in_table);
textBox3->Text=sum.ToString();
for(i=0;i<how_many_in_table;i++)
listBox1->Items->Add(table[i].ToString());
double sqrt_table;
sqrt_table=sqrt(1.0*sum);
textBox4->Text=sqrt_table.ToString();
double value_per_sum;
value_per_sum=(1.0*x+how_many_in_table)/(sum*1.0);
textBox5->Text=value_per_sum.ToString();
double value_mal_sum;
value_mal_sum=(1.0*x*how_many_in_table)/(sum*1.0);
textBox6->Text=value_mal_sum.ToString();
double sqrt_another_sum;
sqrt_another_sum=sqrt(1.0*(x+sum+how_many_in_table));
textBox7->Text=sqrt_another_sum.ToString();
delete table;
 
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
init_Random();
}
};
}

niedziela, 4 września 2016

Graphics^ in Visual C++

I wanted to recall the graphics methods in Visual C++.



#pragma endregion
private:
System::Void init_Random()
{
srand(time(NULL));
}
private:
Graphics^ my_graph;
Pen^ my_pen1;
Pen^ my_pen2;
Pen^ my_pen3;
Pen^ my_pen4;
Pen^ my_pen5;
Pen^ my_pen6;
private:
System::Drawing::Color color1;
System::Drawing::Color color2;
System::Drawing::Color color3;
System::Drawing::Color color4;
System::Drawing::Color color5;
System::Drawing::Color color6;
private:
System::Void init_Graph()
{
my_graph=panel1->CreateGraphics();
color1=System::Drawing::Color::Yellow;
color2=System::Drawing::Color::Blue;
color3=System::Drawing::Color::Red;
color4=System::Drawing::Color::White;
color5=System::Drawing::Color::Violet;
color6=System::Drawing::Color::Green;
my_pen1=gcnew Pen(color1);
my_pen2=gcnew Pen(color2);
my_pen3=gcnew Pen(color3);
my_pen4=gcnew Pen(color4);
my_pen5=gcnew Pen(color5);
my_pen6=gcnew Pen(color6);


}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
init_Graph();
init_Random();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
int centr_x,centr_y,marg=5,i,j;
centr_x=panel1->Width/2;
centr_y=panel1->Height/2;
//frame
my_pen1->Width=3;
my_pen1->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDot;
my_graph->DrawLine(my_pen1,marg,marg,panel1->Width-marg,marg);
my_graph->DrawLine(my_pen1,marg,panel1->Height-marg,panel1->Width-marg,panel1->Height-marg);
my_graph->DrawLine(my_pen1,marg,marg,marg,panel1->Height-marg);
my_graph->DrawLine(my_pen1,panel1->Width-marg,marg,panel1->Width-marg,panel1->Height-marg);
my_pen2->Width=2;
my_pen2->StartCap=System::Drawing::Drawing2D::LineCap::Square;
my_pen2->EndCap=System::Drawing::Drawing2D::LineCap::Round;
my_graph->DrawLine(my_pen2,centr_x,marg,centr_x,panel1->Height-marg);
my_graph->DrawLine(my_pen2,marg,centr_y,panel1->Width-marg,centr_y);
my_pen3->Width=3;
j=30;
    for(i=0;i<4;i++)
{
  my_graph->DrawEllipse(my_pen3,centr_x-j,centr_y-j,j*2,j*2);
  j+=30;
}
Bitmap^ my_bitmap=gcnew Bitmap(panel1->Width,panel1->Height);
System::Drawing::Color temp_color;
for(i=marg;i<panel1->Width-marg;i+=marg)
{
for(j=marg;j<panel1->Height;j+=marg)
{
temp_color=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
my_bitmap->SetPixel(i,j,temp_color);
}
}
my_graph->DrawImage(dynamic_cast<Image^>(my_bitmap),1,1);
my_pen4->Width=5;
my_pen4->StartCap=System::Drawing::Drawing2D::LineCap::RoundAnchor;
my_pen4->EndCap=System::Drawing::Drawing2D::LineCap::ArrowAnchor;
my_pen4->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDot;
my_graph->DrawLine(my_pen4,centr_x,marg,panel1->Width-marg,centr_y);
my_graph->DrawLine(my_pen4,panel1->Width-marg,centr_y,centr_x,panel1->Height-marg);
my_graph->DrawLine(my_pen4,centr_x,panel1->Height-marg,marg,centr_y);
my_graph->DrawLine(my_pen4,marg,centr_y,centr_x,marg);

int x,y,a,h;
x=30,y=30,a=60,h=60;
my_pen5->Width=3;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
x=30,y=panel1->Height-90;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
x=panel1->Width-90,y=30,a=60,h=60;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
y=panel1->Height-90;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
my_pen6->Width=4;
my_pen6->DashCap=System::Drawing::Drawing2D::DashCap::Round;
my_pen6->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDotDot;
my_graph->DrawLine(my_pen6,marg,marg,panel1->Width-marg,panel1->Height-marg);
my_graph->DrawLine(my_pen6,panel1->Width-marg,marg,marg,panel1->Height-marg);


}
};
}

sobota, 3 września 2016

continue first numbers and tables



#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

#define max 500

int sum_table(int *tab, int size)
{
    int i,sum;
    sum=0;
    for(i=0;i<size;i++)
     sum+=tab[i];
    return sum;
}
bool is_first(int x)
{
    int i,sum;
    sum=0;
    for(i=1;i<x+1;i++)
     if(x%i==0)
      ++sum;
    if(sum==2)
     return true;
    else
     return false;
}
void change_table(int *tab1, int *tab2, int size)
{
    int *temp;
    temp=new int[size];
    int i;
    for(i=0;i<size;i++)
     {
         temp[i]=tab1[i];
         tab1[i]=tab2[i];
         tab2[i]=temp[i];
     }
   
    delete temp;
}
int *first_table;
int main(int argc, char **argv)
{
    int i,j,k,sum;
   
   
    srand(time(NULL));
    first_table=new int[max];
    i=0;j=1;
    do
    {
        if(is_first(j))
        {
            first_table[i]=j;
            ++i;
        }
        ++j;
    }while(i<max);
    int table_testing[max][max],double_first[max][max],f_value[max][max];
    int g_value[max][max],h_value[max],i_value[max][max];
    for(i=0;i<max;i++)
    {
     for(j=0;j<max;j++)
     {
      k=rand()%max;   
      table_testing[i][j]=first_table[k];
      double_first[i][j]=first_table[j];
      if(double_first[i][j]>=table_testing[i][j])
       f_value[i][j]=double_first[i][j]-table_testing[i][j];
      else
       f_value[i][j]=table_testing[i][j]-double_first[i][j];
      if(is_first(f_value[i][j]))
      {
       g_value[i][j]=1;
       i_value[i][j]=0;
      }
      else
      {
       g_value[i][j]=0;
       i_value[i][j]=1;
      }
     }
    }
    for(i=0;i<max;i++)
    {
        for(j=0;j<max;j++)
        {
            h_value[i]=sum_table(g_value[i],max);
            h_value[i]+=sum_table(i_value[i],max);
        }
    }
    for(i=0;i<max;i++)
    {
        for(j=0;j<h_value[i];j++)
        {
            change_table(double_first[j],table_testing[j],h_value[i]);
        }
    }
   

    delete first_table;
    return 0;
}