niedziela, 23 października 2016

Simple Calendar in C++ Builder


void __fastcall TForm4::FormCreate(TObject *Sender)
{
 Edit1->Text=DateToStr(CCalendar1->CalendarDate);
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button1Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm4::CCalendar1Change(TObject *Sender)
{
 Caption="Year-Month-Day  "+DateToStr(CCalendar1->CalendarDate);
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button2Click(TObject *Sender)
{
 CCalendar1->PrevYear();
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button3Click(TObject *Sender)
{
 CCalendar1->PrevMonth();
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button4Click(TObject *Sender)
{
 CCalendar1->NextYear();
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button5Click(TObject *Sender)
{
 CCalendar1->NextMonth();
}

piątek, 21 października 2016

Visual C++ drawing triangle or ellipse in 8 colors


#pragma endregion
private: Graphics^ g;
private: Pen^ my_pen1;
Pen^ my_pen2;
Pen^ my_pen3;
Pen^ my_pen4;
Pen^ my_pen5;
Pen^ my_pen6;
Pen^ my_pen7;
Pen^ my_pen8;
private: System::Void init_Graphics()
{
g=panel1->CreateGraphics();
my_pen1=gcnew Pen(System::Drawing::Color::Red);
my_pen2=gcnew Pen(System::Drawing::Color::Brown);
my_pen3=gcnew Pen(System::Drawing::Color::Green);
my_pen4=gcnew Pen(System::Drawing::Color::Lime);
my_pen5=gcnew Pen(System::Drawing::Color::Purple);
my_pen6=gcnew Pen(System::Drawing::Color::Blue);
my_pen7=gcnew Pen(System::Drawing::Color::Black);
my_pen8=gcnew Pen(System::Drawing::Color::Orange);
}
private: System::Void draw_Triangle(int x1,int y1, int x2, int y2, int x3, int y3, Pen ^pen)
 {
 g->DrawLine(pen,x1,y1,x2,y2);
 g->DrawLine(pen,x2,y2,x3,y3);
 g->DrawLine(pen,x3,y3,x1,y1);
 }
 private: System::Void draw_Ellipse(int x, int y, int width, int height, Pen ^pen)
  {
  g->DrawEllipse(pen,x,y,width,height);
  }
 

private: System::Void init_Random()
{
srand(time(NULL));
}
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();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
init_Graphics();
 
int i,j,k;
System::Int32 how_many;
int x1,y1,x2,y2,x3,y3;
int x_ellipse,y_ellipse,w,h;
how_many=Int32::Parse(textBox1->Text);
for(i=0;i<how_many;i++)
{
                     k=rand()%2;
if(k==0)
{
                      j=rand()%8;
 switch(j)
 {
 case 0: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen1);break;
 case 1: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen2);break;
 case 2: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen3);break;
 case 3: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen4);break;
 case 4: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen5);break;
 case 5: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen6);break;
 case 6: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen7);break;
 case 7: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen8);break;
 }
}
else
{
j=rand()%8;
switch(j)
{
case 0: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen1);break;
case 1: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen2);break;
case 2: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen3);break;
case 3: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen4);break;
case 4: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen5);break;
case 5: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen6);break;
case 6: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen7);break;
case 7: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen8);break;

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


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