poniedziałek, 21 grudnia 2020
StringGrid and fstream (C++ Builder)
niedziela, 13 grudnia 2020
pthread_create gcc
#include <stdio.h>
#include <pthread.h>
int even_Numbers(int value)
{
if(value%2==0)
return 1;
else
return 0;
}
int odd_Numbers(int value)
{
if(value%2!=0)
return 1;
else
return 0;
}
void write_Even(void* sd)
{
int l=1;
while(1)
{
if(even_Numbers(l))
fprintf(stderr,"%d\n",l);
++l;
}
return NULL;
}
void write_Odd(void* sd)
{
int l=1;
while(1)
{
if(odd_Numbers(l))
fprintf(stderr,"%d\n",l);
++l;
}
return NULL;
}
pthread_t new_Thread;
int main()
{
pthread_create(&new_Thread,NULL,&write_Odd,NULL);
while(1)
write_Even(stderr);
return 0;
}
czwartek, 3 grudnia 2020
Right triangles with prime numbers (C++)
#include <iostream>
#define gg 1000
using namespace std;
struct m_Point
{
int x;
int y;
int z;
};
int *TAB1,*TAB2;
bool is_Traingle(int a, int b, int c)
{
bool value=false;
if((a*a)+(b*b)==(c*c))
value=true;
if((a*a)+(c*c)==(b*b))
value=true;
if((b*b)+(c*c)==(a*a))
value=true;
return value;
}
bool is_First(int value)
{
int i,sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
void init_Tab()
{
int i,j;
TAB1=new int[gg];
TAB2=new int[gg];
i=0;
j=2;
do
{
if(is_First(j))
{
TAB1[i]=j;
++i;
}
++j;
}while(i<gg);
i=0;
j=1;
do
{
if(!is_First(j))
{
TAB2[i]=j;
++i;
}
++j;
}while(i<gg);
}
void delete_Tab()
{
delete TAB2;
delete TAB1;
}
int main(int argc, char **argv)
{
int i,j,k,l=0;
init_Tab();
struct m_Point *TR=new struct m_Point[gg];
for(i=0;i<gg;i++)
{
TR[i].x=0;
TR[i].y=0;
TR[i].z=0;
}
for(i=0;i<gg;i++)
{
for(j=0;j<gg;j++)
{
for(k=0;k<gg;k++)
{
if(is_Traingle(TAB1[i],TAB2[j],TAB2[k]))
{
TR[l].x=TAB1[i];TR[l].y=TAB2[j];TR[l].z=TAB2[k];
++l;
}
if(is_Traingle(TAB1[i],TAB1[i],TAB2[k]))
{
TR[l].x=TAB1[i];TR[l].y=TAB2[j];TR[l].z=TAB2[k];
++l;
}
if(is_Traingle(TAB1[i],TAB1[i],TAB1[k]))
{
TR[l].x=TAB1[i];TR[l].y=TAB2[j];TR[l].z=TAB2[k];
++l;
}
}
}
}
for(i=0;i<l;i++)
{
cout<<i+1<<") "<<TR[i].x<<" - "<<TR[i].y<<" - "<<TR[i].z<<endl;
}
delete [] TR;
delete_Tab();
return 0;
}
YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL
środa, 11 listopada 2020
Writing a StringGrid to a file (C++ Builder)
#include <Grids.hpp>
void __fastcall TForm1::save_SG(TStringGrid *table,UnicodeString filename)
{
UnicodeString **values;
int i,j,size_x,size_y;
size_x=table->ColCount;
size_y=table->RowCount;
values=new UnicodeString *[size_x];
for(i=0;i<size_x;i++)
values[i]=new UnicodeString[size_y];
for(i=0;i<size_x;i++)
for(j=0;j<size_y;j++)
values[i][j]=table->Cells[i][j];
std::auto_ptr<TStreamWriter> write_Data(new TStreamWriter(filename,false));
for(i=0;i<size_x;i++)
for(j=0;j<size_y;j++)
write_Data->WriteLine(values[i][j]);
for(i=0;i<size_x;i++)
delete [] values[i];
delete [] values;
}
YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL
wtorek, 10 listopada 2020
Swap double arrays (C++ - new/delete)
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void change_Arrays(int** tab1, int** tab2, int m_size)
{
int **temp;
int i,j;
temp=new int *[m_size];
for(i=0;i<m_size;i++)
temp[i]=new int[m_size];
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
temp[i][j]=tab1[i][j];
}
}
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
tab1[i][j]=tab2[i][j];
}
}
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
tab2[i][j]=temp[i][j];
}
}
for(i=0;i<m_size;i++)
delete [] temp[i];
delete [] temp;
}
int sum_double_Array(int **tab, int m_size)
{
int i,j,sum;
sum=0;
for(i=0;i<m_size;i++)
for(j=0;j<m_size;j++)
sum+=tab[i][j];
return sum;
}
double aver_double_Array(int **tab, int m_size)
{
double aver;
aver=(1.00*sum_double_Array(tab,m_size))/(1.00*m_size);
return aver;
}
int main()
{
srand(time(NULL));
int i,j,k;
int **tab1,**tab2;
int sum1, sum2;
double aver1,aver2;
k=20;
tab1=new int *[k];
tab2=new int *[k];
for(i=0;i<k;i++)
{
tab1[i]=new int[k];
tab2[i]=new int[k];
}
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
tab1[i][j]=rand()%k+1;
tab2[i][j]=rand()%k+1;
}
}
sum1=sum_double_Array(tab1,k);
sum2=sum_double_Array(tab2,k);
aver1=aver_double_Array(tab1,k);
aver2=aver_double_Array(tab2,k);
cout<<"Sum table 1: "<<sum1<<endl;
cout<<"Sum table 2: "<<sum2<<endl;
cout<<"Aver table 1: "<<aver1<<endl;
cout<<"Aver table 2: "<<aver2<<endl;
change_Arrays(tab1,tab2,k);
sum1=sum_double_Array(tab1,k);
sum2=sum_double_Array(tab2,k);
aver1=aver_double_Array(tab1,k);
aver2=aver_double_Array(tab2,k);
cout<<"AFTER CHANGE: \n";
sum1=sum_double_Array(tab1,k);
sum2=sum_double_Array(tab2,k);
aver1=aver_double_Array(tab1,k);
aver2=aver_double_Array(tab2,k);
cout<<"Sum table 1: "<<sum1<<endl;
cout<<"Sum table 2: "<<sum2<<endl;
cout<<"Aver table 1: "<<aver1<<endl;
cout<<"Aver table 2: "<<aver2<<endl;
change_Arrays(tab1,tab2,k);
sum1=sum_double_Array(tab1,k);
sum2=sum_double_Array(tab2,k);
aver1=aver_double_Array(tab1,k);
aver2=aver_double_Array(tab2,k);
for(i=0;i<k;i++)
{
delete [] tab2[i];
delete [] tab1[i];
}
delete [] tab2;
delete [] tab1;
return 0;
}
YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL
niedziela, 23 sierpnia 2020
Calculations in structures
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#define max_Size 1000
#define rand_Size 100
using namespace std;
struct int_Point
{
int x;
int y;
int z;
};
struct float_Point
{
float x;
float y;
float z;
};
bool min_Sort(int a, int b, int c)
{
if((a<b) && (b<c))
return true;
else
return false;
}
int main()
{
int a,b,c,i;
float a1,b1,c1;
float a2,b2,c2;
int a3,b3,c3;
srand(time(NULL));
int_Point *i_P;
float_Point *f_P;
float_Point *g_P;
int_Point *h_P;
i_P=new struct int_Point[max_Size];
f_P=new struct float_Point[max_Size];
g_P=new struct float_Point[max_Size];
h_P=new struct int_Point[max_Size];
for(i=0;i<max_Size;i++)
{
a=1+rand()%rand_Size; a1=(a*1.00)/100.;a2=1.00-a1;a3=int(a2*100.);
b=1+rand()%rand_Size; b1=(b*1.00)/100.;b2=1.00-b1;b3=int(b2*100.);
c=1+rand()%rand_Size; c1=(c*1.00)/100.;c2=1.00-c1;c3=int(c2*100.);
i_P[i].x=a; f_P[i].x=a1; g_P[i].x=a2; h_P[i].x=a3;
i_P[i].y=b; f_P[i].y=b1; g_P[i].y=b2; h_P[i].y=b3;
i_P[i].z=c; f_P[i].z=c1; g_P[i].z=c2; h_P[i].z=c3;
if(min_Sort(a,b,c))
{
float *sum;
sum=new float[3];
sum[0]=(1.00*i_P[i].x)+f_P[i].x+g_P[i].x+(1.00*h_P[i].x);
sum[1]=(1.00*i_P[i].y)+f_P[i].y+g_P[i].y+(1.00*h_P[i].y);
sum[2]=(1.00*i_P[i].z)+f_P[i].z+g_P[i].z+(1.00*h_P[i].z);
float all_s=sum[0]+sum[1]+sum[3];
cout<<i_P[i].x<<"+"<<f_P[i].x<<"+"<<g_P[i].x<<"+"<<h_P[i].x<<"="<<sum[0]<<endl;
cout<<i_P[i].y<<"+"<<f_P[i].y<<"+"<<g_P[i].y<<"+"<<h_P[i].y<<"="<<sum[1]<<endl;
cout<<i_P[i].z<<"+"<<f_P[i].z<<"+"<<g_P[i].z<<"+"<<h_P[i].z<<"="<<sum[2]<<endl;
cout<<"All = "<<all_s<<endl;
delete [] sum;
}
}
delete [] i_P;
delete [] f_P;
delete [] g_P;
delete [] h_P;
getch();
return 0;
}
YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL
sobota, 22 sierpnia 2020
Copying files /proc
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sendfile.h>
using namespace std;
class COPY_SENDF
{
private:
int file_begin;
int file_end;
string name_begin;
string name_end;
struct stat str_stat;
off_t temp_off;
public:
void read(string name1, string name2)
{
name_begin=name1;
name_end=name2;
}
void s_Copy()
{
file_begin=open(name_begin.c_str(),O_RDONLY);
fstat(file_begin,&str_stat);
file_end=open(name_end.c_str(),O_WRONLY | O_CREAT,str_stat.st_mode);
sendfile(file_end,file_begin,&temp_off,str_stat.st_size);
close(file_begin);
close(file_end);
}
};
string write_proc(string name)
{
string result;
result="/proc/"+name;
return result;
}
int main(int argc, char **argv)
{
string info="/home/PROC_DATES";
string files_proc[8]={"filesystems","version","meminfo","modules","iomen",
"partitions","swap","cpuinfo"};
COPY_SENDF *c_Send=new class COPY_SENDF[8];
for(int i=0;i<8;i++)
{
c_Send[i].read(write_proc(files_proc[i]),info);
c_Send[i].s_Copy();
}
delete [] c_Send;
return 0;
}
YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL
czwartek, 23 lipca 2020
Combining data in tables (C++)
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
string add_Tab(int *t1, int *t2, int s)
{
#define buf_s 20
int i,j,k;
int *temp=new int[s*2];
char **tab_Buff;
for(i=0,j=0,k=1;i<s;i++,j+=2,k+=2)
{
temp[j]=t1[i];
temp[k]=t2[i];
}
tab_Buff=new char *[s*2];
for(i=0;i<s*2;i++)
{
tab_Buff[i]=new char[buf_s];
}
string string_Tab;
for(i=0;i<s*2;i++)
{
snprintf(tab_Buff[i],sizeof(tab_Buff[i]),"%d",temp[i]);
}
for(i=0;i<s*2;i++)
string_Tab+=tab_Buff[i];
delete temp;
for(i=0;i<s*2;i++)
delete [] tab_Buff[i];
delete tab_Buff;
return string_Tab;
}
int main(int argc, char **argv)
{
int tab1[5]={0,2,4,6,8};
int tab2[5]={-1,-3,-5,-7,-9};
string connect_T=add_Tab(tab1,tab2,5);
cout<<connect_T<<endl;
return 0;
}
niedziela, 24 maja 2020
Sendfile (linux, g++)
#include <string>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#define size_F 7
using namespace std;
string base_Proc[size_F]={"/proc/cpuinfo","/proc/version","/proc/meminfo","/proc/partitions","/proc/keys","/proc/cgroups","/proc/devices"};
string my_Files[size_F]={"CPU","VERSION","MEMINFO","PARTITIONS","KEYS","CGROUPS","DEVICES"};
int file_R[size_F],file_W[size_F];
struct stat* info_S;
off_t *offset_F;
int main(int argc, char **argv)
{
info_S=new struct stat[size_F];
offset_F=new off_t[size_F];
for(int i=0;i<size_F;i++)
{
file_R[i]=open(base_Proc[i].c_str(),O_RDONLY);
fstat(file_R[i],&info_S[i]);
file_W[i]=open(my_Files[i].c_str(),O_WRONLY | O_CREAT,info_S[i].st_mode);
sendfile(file_W[i],file_R[i],&offset_F[i],info_S[i].st_size);
close(file_R[i]);
close(file_W[i]);
}
delete offset_F;
delete info_S;
return 0;
}
poniedziałek, 18 maja 2020
Arrays and saving data to a files (C++ fstream)
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <fstream>
#define min_S 10
#define max_S 1000
using namespace std;
struct date_Tab
{
int min_T;
int max_T;
int sum_T;
double aver_T;
};
fstream file_Tab,file_Report;
string name_Files[2]={"f_Tab.txt","f_Report.txt"};
int** main_Tab;
int first_Values[max_S];
void sort_Tab(int* tab, int size_Tab)
{
int i,j,k;
for(i=1;i<size_Tab;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
bool is_First(int value)
{
int i,sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
void write_first_Tab()
{
int i,j;
i=0;
j=2;
do
{
if(is_First(j))
{
first_Values[i]=j;
++i;
}
++j;
}while(i<max_S);
}
int sum_Tab(int* tab, int size_T)
{
int i,sum=0;
for(i=0;i<size_T;i++)
sum+=tab[i];
return sum;
}
double aver_Tab(int* tab, int size_T)
{
double aver;
aver=(1.00*sum_Tab(tab,size_T))/(1.00*size_T);
return aver;
}
int min_Tab(int* tab, int size_T)
{
int i,min_T;
min_T=tab[0];
for(i=1;i<size_T;i++)
if(min_T>tab[i])
min_T=tab[i];
return min_T;
}
int max_Tab(int* tab, int size_T)
{
int i,max_T;
max_T=tab[0];
for(i=1;i<size_T;i++)
if(max_T<tab[i])
max_T=tab[i];
return max_T;
}
int main()
{
int i,j,k;
struct date_Tab* values_Tab=new struct date_Tab[max_S];
main_Tab=new int *[max_S];
for(i=0;i<max_S;i++)
main_Tab[i]=new int[min_S];
srand(time(NULL));
write_first_Tab();
i=0;
do
{
for(j=0;j<min_S;j++)
{
k=rand()%max_S;
main_Tab[i][j]=first_Values[k];
}
++i;
}while(i<max_S);
for(i=0;i<max_S;i++)
sort_Tab(main_Tab[i],min_S);
for(i=0;i<max_S;i++)
{
values_Tab[i].min_T=min_Tab(main_Tab[i],min_S);
values_Tab[i].max_T=max_Tab(main_Tab[i],min_S);
values_Tab[i].sum_T=sum_Tab(main_Tab[i],min_S);
values_Tab[i].aver_T=aver_Tab(main_Tab[i],min_S);
}
file_Tab.open(name_Files[0].c_str(),ios::out);
for(i=0;i<max_S;i++)
{
for(j=0;j<min_S;j++)
{
file_Tab<<main_Tab[i][j]<<" ";
}
file_Tab<<"\n";
}
file_Tab.close();
file_Report.open(name_Files[1].c_str(),ios::out);
for(i=0;i<max_S;i++)
{
file_Report<<values_Tab[i].min_T<<" "<<values_Tab[i].max_T<<" "
<<values_Tab[i].sum_T<<" "<<values_Tab[i].aver_T;
file_Report<<"\n";
}
file_Report.close();
for(i=0;i<max_S;i++)
delete[] main_Tab[i];
delete [] main_Tab;
delete [] values_Tab;
getch();
return 0;
}
wtorek, 5 maja 2020
Tables and StringGrid - C++ Builder
: TForm(Owner)
{
srand(time(NULL));
}
double __fastcall TForm1::min_Fraction(int *tab1, int size1, int *tab2, int size2)
{
int i,sum1,sum2;
double fraction;
sum1=sum2=0;
for(i=0;i<size1;i++)
sum1+=tab1[i];
for(i=0;i<size2;i++)
sum2+=tab2[i];
if(sum1<sum2)
fraction=(1.0*sum1)/(1.0*sum2);
else
fraction=(1.0*sum2)/(1.0*sum1);
return fraction;
}
double __fastcall TForm1::max_Fraction(int *tab1, int size1, int *tab2, int size2)
{
int i,sum1,sum2;
double fraction;
sum1=sum2=0;
for(i=0;i<size1;i++)
sum1+=tab1[i];
for(i=0;i<size2;i++)
sum2+=tab2[i];
if(sum1>sum2)
fraction=(1.0*sum1)/(1.0*sum2);
else
fraction=(1.0*sum2)/(1.0*sum1);
return fraction;
}
void __fastcall TForm1::sort_Array(int *tab, int size)
{
int i,j,k;
for(i=1;i<size;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
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::FormCreate(TObject *Sender)
{
Label1->Caption=DateToStr(Date());
int i,j;
i=0;
j=2;
do
{
if(is_First(j))
{
temp_F[i]=j;
++i;
}
++j;
}while(i<100);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
TDateTime DateTime = Time();
Label2->Caption=TimeToStr(DateTime);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
int first_Tab1[10][10],first_Tab2[10][10],sum_Tab[10][20],i,j,k,l,r1,r2;
double min_Fract[10],max_Fract[10];
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
r1=rand()%100;
r2=rand()%100;
first_Tab1[i][j]=temp_F[r1];
first_Tab2[i][j]=temp_F[r2];
}
}
for(i=0;i<10;i++)
{
sort_Array(first_Tab1[i],10);
sort_Array(first_Tab2[i],10);
}
for(i=0;i<10;i++)
{
min_Fract[i]=min_Fraction(first_Tab1[i],10,first_Tab2[i],10);
max_Fract[i]=max_Fraction(first_Tab1[i],10,first_Tab2[i],10);
}
for(i=0;i<10;i++)
{
for(j=0,k=0,l=1;j<10;j++,k+=2,l+=2)
{
sum_Tab[i][k]=first_Tab1[i][j];
sum_Tab[i][l]=first_Tab2[i][j];
}
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
StringGrid1->Cells[i][j]=IntToStr(first_Tab1[j][i]);
StringGrid2->Cells[i][j]=IntToStr(first_Tab2[j][i]);
}
StringGrid4->Cells[0][i]=FloatToStr(min_Fract[i]);
StringGrid4->Cells[1][i]=FloatToStr(max_Fract[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<20;j++)
{
StringGrid3->Cells[j][i]=IntToStr(sum_Tab[i][j]);
}
}
}
niedziela, 19 kwietnia 2020
Floyds algorithm (C++ Builder)
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
srand(time(NULL));
}
//---------------------------------------------------------------------------
int min_Array(int a, int b)
{
if(a<b)
return a;
else
return b;
}
int max_Array(int a, int b)
{
if(a>b)
return a;
else
return b;
}
void __fastcall TForm1::init_minus_One(int **tab, int t_Size)
{
for(int i=0;i<t_Size;i++)
for(int j=0;j<t_Size;j++)
tab[i][j]=-1;
}
void __fastcall TForm1::init_temp_Zero(int *tab, int t_Size)
{
for(int i=0;i<t_Size;i++)
tab[i]=0;
}
void __fastcall TForm1::min_Floyd(int **tab, int size)
{
int i,j,k;
for(i=0;i<size;i++)
for(j=0;j<size;j++)
for(k=0;k<size;k++)
tab[j][k]=min_Array(tab[j][k],tab[j][i]+tab[i][k]);
}
void __fastcall TForm1::max_Floyd(int **tab, int size)
{
int i,j,k;
for(i=0;i<size;i++)
for(j=0;j<size;j++)
for(k=0;k<size;k++)
tab[j][k]=max_Array(tab[j][k],tab[j][i]+tab[i][k]);
}
void __fastcall max_Floyd(int **tab, int size);
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i,j,k,random_V;
int **FLOYD_TABLE;
int *temp_table_X;
int *temp_table_Y;
FLOYD_TABLE=new int *[size_FL];
for(i=0;i<size_FL;i++)
FLOYD_TABLE[i]=new int[size_FL];
temp_table_X=new int[size_FL];
temp_table_Y=new int[size_FL];
init_minus_One(FLOYD_TABLE,size_FL);
init_temp_Zero(temp_table_Y,size_FL);
init_temp_Zero(temp_table_X,size_FL);
random_V=rand()%(64-16)+16;
Edit1->Text="RANDOM VALUES TABLE= "+IntToStr(random_V);
i=0;
do
{
j=rand()%size_FL;
if(temp_table_X[j]==0)
{
temp_table_X[j]=1;
++i;
}
}while(i<random_V);
i=0;
do
{
j=rand()%size_FL;
if(temp_table_Y[j]==0)
{
temp_table_Y[j]=1;
++i;
}
}while(i<random_V);
int *index_X,*index_Y;
index_X=new int[random_V];
index_Y=new int[random_V];
i=0;
j=0;
do
{
if(temp_table_X[j]==1)
{
index_X[i]=j;
++i;
}
++j;
}while(i<random_V);
i=0;
j=0;
do
{
if(temp_table_Y[j]==1)
{
index_Y[i]=j;
++i;
}
++j;
}while(i<random_V);
for(i=0;i<random_V;i++)
{
FLOYD_TABLE[index_X[i]][index_Y[i]]=rand()%(360-10)+10;
}
for(i=0;i<size_FL;i++)
for(j=0;j<size_FL;j++)
StringGrid1->Cells[j][i]=IntToStr(FLOYD_TABLE[i][j]);
int **FLOYD_MAX;
int **FLOYD_MIN;
FLOYD_MIN=new int *[size_FL];
FLOYD_MAX=new int *[size_FL];
for(i=0;i<size_FL;i++)
{
FLOYD_MAX[i]=new int[size_FL];
FLOYD_MIN[i]=new int[size_FL];
}
for(i=0;i<size_FL;i++)
{
for(j=0;j<size_FL;j++)
{
FLOYD_MAX[i][j]=FLOYD_TABLE[i][j];
FLOYD_MIN[i][j]=FLOYD_TABLE[i][j];
}
}
min_Floyd(FLOYD_MIN,size_FL);
max_Floyd(FLOYD_MAX,size_FL);
for(i=0;i<size_FL;i++)
{
for(j=0;j<size_FL;j++)
{
if(FLOYD_MIN[i][j]!=-1 && i!=j)
ListBox1->Items->Add(IntToStr(i)+"--->"+IntToStr(j)+" = "+IntToStr(FLOYD_MIN[i][j]));
}
}
for(i=0;i<size_FL;i++)
{
for(j=0;j<size_FL;j++)
{
if(FLOYD_MAX[i][j]!=-1 && i!=j)
ListBox2->Items->Add(IntToStr(i)+"--->"+IntToStr(j)+" = "+IntToStr(FLOYD_MAX[i][j]));
}
}
for(i=0;i<size_FL;i++)
{
delete FLOYD_TABLE[i];
delete FLOYD_MIN[i];
delete FLOYD_MAX[i];
}
delete [] FLOYD_TABLE;
delete [] FLOYD_MIN;
delete [] FLOYD_MAX;
delete temp_table_X;
delete temp_table_Y;
delete index_X;
delete index_Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
poniedziałek, 6 kwietnia 2020
Use DataGridView (Visual C++)
private: System::Void Sort(int *tab, int size)
{
int i,j,k;
for(i=1;i<size;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
private: System::Double sum_double_Tab(double *tab, int size)
{
double sum;
sum=0.0;
for(int i=0;i<size;i++)
sum+=tab[i];
return sum;
}
private: System::Int64 sum_int_Tab(int *tab, int size)
{
int sum;
sum=0;
for(int i=0;i<size;i++)
sum+=tab[i];
return sum;
}
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));
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int i,j;
DataGridViewCellStyle^ grids_Style1=gcnew DataGridViewCellStyle();
DataGridViewCellStyle^ grids_Style2=gcnew DataGridViewCellStyle();
DataGridViewCellStyle^ grids_Style3=gcnew DataGridViewCellStyle();
System::Drawing::Font^ font_Grid1=gcnew System::Drawing::Font(System::Drawing::FontFamily::GenericSansSerif,16,FontStyle::Regular);
System::Drawing::Font^ font_Grid2=gcnew System::Drawing::Font(System::Drawing::FontFamily::GenericSansSerif,16,FontStyle::Underline);
System::Drawing::Font^ font_Grid3=gcnew System::Drawing::Font(System::Drawing::FontFamily::GenericSansSerif,16,FontStyle::Italic);
dataGridView2->ColumnCount=1;
dataGridView2->RowCount=5;
grids_Style2->Font=font_Grid2;
grids_Style2->ForeColor=System::Drawing::Color::Green;
dataGridView2->DefaultCellStyle=grids_Style2;
dataGridView2->DefaultCellStyle->BackColor=Color::Coral;
dataGridView2->Columns[0]->Width=95;
for(i=0;i<5;i++)
dataGridView2->Rows[i]->Height=30;
grids_Style2->Font=font_Grid2;
grids_Style2->ForeColor=System::Drawing::Color::Green;
dataGridView2->DefaultCellStyle=grids_Style2;
dataGridView2->Rows[0]->Cells[0]->Value="NUMBERS: ";
dataGridView2->Rows[1]->Cells[0]->Value="1/n";
dataGridView2->Rows[2]->Cells[0]->Value="sqrt(n)";
dataGridView2->Rows[3]->Cells[0]->Value="sin(n)";
dataGridView2->Rows[4]->Cells[0]->Value="cos(n)";
dataGridView1->ColumnCount=10;
dataGridView1->RowCount=5;
dataGridView1->DefaultCellStyle->BackColor=Color::Yellow;
dataGridView1->AlternatingRowsDefaultCellStyle->BackColor=Color::Red;
for(i=0;i<10;i++)
dataGridView1->Columns[i]->Width=90;
for(i=0;i<5;i++)
dataGridView1->Rows[i]->Height=30;
grids_Style1->Font=font_Grid1;
grids_Style1->ForeColor=System::Drawing::Color::Brown;
dataGridView1->DefaultCellStyle=grids_Style1;
int tab_Numbers[10];
double one_Tab[10],sqrt_Tab[10],sin_Tab[10],cos_Tab[10];
for(i=0;i<10;i++)
{
tab_Numbers[i]=rand()%360+1;
}
Sort(tab_Numbers,10);
for(i=0;i<10;i++)
{
one_Tab[i]=1./(double(tab_Numbers[i]*1.00));
sqrt_Tab[i]=sqrt(double(tab_Numbers[i]*1.00));
sin_Tab[i]=sin(double(tab_Numbers[i]*1.00));
cos_Tab[i]=cos(double(tab_Numbers[i]*1.00));
}
for(i=0;i<10;i++)
{
dataGridView1->Rows[0]->Cells[i]->Value=(tab_Numbers[i]).ToString();
dataGridView1->Rows[1]->Cells[i]->Value=one_Tab[i].ToString();
dataGridView1->Rows[2]->Cells[i]->Value=sqrt_Tab[i].ToString();
dataGridView1->Rows[3]->Cells[i]->Value=sin_Tab[i].ToString();
dataGridView1->Rows[4]->Cells[i]->Value=cos_Tab[i].ToString();
}
dataGridView3->ColumnCount=1;
dataGridView3->RowCount=5;
dataGridView3->DefaultCellStyle->BackColor=Color::BlueViolet;
dataGridView3->Columns[0]->Width=100;
for(i=0;i<5;i++)
dataGridView3->Rows[i]->Height=30;
grids_Style3->Font=font_Grid3;
grids_Style3->ForeColor=System::Drawing::Color::DarkOrange;
dataGridView3->DefaultCellStyle=grids_Style3;
int sum_Num;
double sum_One,sum_Sqrt,sum_Sin,sum_Cos;
sum_Num=sum_int_Tab(tab_Numbers,10);
sum_One=sum_double_Tab(one_Tab,10);
sum_Sqrt=sum_double_Tab(sqrt_Tab,10);
sum_Sin=sum_double_Tab(sin_Tab,10);
sum_Cos=sum_double_Tab(cos_Tab,10);
dataGridView3->Rows[0]->Cells[0]->Value=sum_Num.ToString();
dataGridView3->Rows[1]->Cells[0]->Value=sum_One.ToString();
dataGridView3->Rows[2]->Cells[0]->Value=sum_Sqrt.ToString();
dataGridView3->Rows[3]->Cells[0]->Value=sum_Sin.ToString();
dataGridView3->Rows[4]->Cells[0]->Value=sum_Cos.ToString();
}
};
}
środa, 1 kwietnia 2020
Calculations in files
#include <iostream>
#include <fstream>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define max_SIZE 1000
#define block_SIZE 50
using namespace std;
struct DATE
{
double min_D;
double max_D;
double aver1;
double aver2;
double sum;
};
double sum_Table(double *tab, int t_Size)
{
double sum=0.0;
for(int i=0;i<t_Size;i++)
sum+=tab[i];
return sum;
}
double min_Table(double *tab, int t_Size)
{
double min_T=tab[0];
for(int i=0;i<t_Size;i++)
if(min_T>tab[i])
min_T=tab[i];
return min_T;
}
double max_Table(double *tab, int t_Size)
{
double max_T=tab[0];
for(int i=0;i<t_Size;i++)
if(max_T<tab[i])
max_T=tab[i];
return max_T;
}
double aver_Table(double *tab, int t_Size)
{
double aver_T;
aver_T=sum_Table(tab,t_Size)/(1.0*t_Size);
return aver_T;
}
double aver_min_max_Table(double *tab, int t_Size)
{
double a_mm_T;
a_mm_T=(max_Table(tab,t_Size)+(min_Table(tab,t_Size)))/2.0;
return a_mm_T;
}
void sort_Tab(double *tab, int t_Size)
{
int i,j;
double k;
for(i=1;i<t_Size;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
bool is_First(int value)
{
int sum=0;
for(int i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
int *main_Tab;
double **sqrt_Table;
int main()
{
int i,j,k;
double l;
fstream table_S,report_S;
main_Tab=new int[max_SIZE];
sqrt_Table=new double *[block_SIZE];
for(i=0;i<block_SIZE;i++)
sqrt_Table[i]=new double[block_SIZE];
struct DATE *file_Date=new DATE[block_SIZE];
srand(time(NULL));
i=0;j=2;
do
{
if(is_First(j))
{
main_Tab[i]=j;
++i;
}
++j;
}while(i<max_SIZE);
for(i=0;i<block_SIZE;i++)
{
for(j=0;j<block_SIZE;j++)
{
k=rand()%max_SIZE;
l=sqrt(1.00*main_Tab[k]);
sqrt_Table[i][j]=l;
}
}
for(i=0;i<block_SIZE;i++)
sort_Tab(sqrt_Table[i],block_SIZE);
for(i=0;i<block_SIZE;i++)
{
file_Date[i].min_D=min_Table(sqrt_Table[i],block_SIZE);
file_Date[i].max_D=max_Table(sqrt_Table[i],block_SIZE);
file_Date[i].aver1=aver_Table(sqrt_Table[i],block_SIZE);
file_Date[i].aver2=aver_min_max_Table(sqrt_Table[i],block_SIZE);
file_Date[i].sum=sum_Table(sqrt_Table[i],block_SIZE);
}
table_S.open("table_SQRT.txt",ios::out);
for(i=0;i<block_SIZE;i++)
{
for(j=0;j<block_SIZE;j++)
{
table_S<<sqrt_Table[i][j];
}
table_S<<"\n";
}
table_S.close();
report_S.open("REPORT.txt",ios::out);
for(i=0;i<block_SIZE;i++)
{
report_S<<file_Date[i].max_D<<" - "<<file_Date[i].max_D<<" - "<<file_Date[i].aver1<<" - "<<file_Date[i].aver2<<" -"<<file_Date[i].sum;
report_S<<"\n";
}
delete main_Tab;
for(i=0;i<block_SIZE;i++)
delete [] sqrt_Table[i];
delete [] sqrt_Table;
delete file_Date;
getch();
return 0;
}
sobota, 28 marca 2020
Chessboard C
#define size_Board 8
#define max_Value size_Board*size_Board
char S[size_Board];
char I[size_Board];
char main_Board[max_Value][2];
void init_Boards()
{
char a='A',b='1';
int i;
for(i=0;i<size_Board;i++)
{
S[i]=a;
I[i]=b;
++a;
++b;
}
}
int main(int argc, char **argv)
{
int i,j,k,l;
init_Boards();
k=0;
for(i=0;i<size_Board;i++)
{
for(j=0;j<size_Board;j++)
{
main_Board[k][0]=S[i];
main_Board[k][1]=I[j];
++k;
}
}
k=1;
for(l=0;l<max_Value;l++)
{
printf("%c%c ",main_Board[l][0],main_Board[l][1]);
if(k%size_Board==0)
printf("\n");
++k;
}
return 0;
}