#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
class ciphere_Text
{
private:
struct base_Josephus
{
int x_J;
base_Josephus *next_Base;
base_Josephus(int temp_Jos,base_Josephus *t_J)
{
x_J=temp_Jos;
next_Base=t_J;
}
};
int result_Josephus(char x,int y)
{
int i,j,k;
int p1,p2;
p1=int_Value(x);p2=y;
typedef base_Josephus *main_Jos;
main_Jos temp_Main1=new base_Josephus(1,0);
temp_Main1->next_Base=temp_Main1;
main_Jos temp_Main2=temp_Main1;
for(i=2;i<=p1;i++)
temp_Main2=(temp_Main2->next_Base=new base_Josephus(i,temp_Main2));
while(temp_Main2!=temp_Main2->next_Base)
{
for(j=1;j<p2;j++)
temp_Main2=temp_Main2->next_Base;
temp_Main2->next_Base=temp_Main2->next_Base->next_Base;
}
k=temp_Main2->x_J;
return k;
}
char *c_Text;
int size_Text;
int int_Value(char x)
{
int i,j;
char a;
char m_Text[26],p_Text[26];
j=0;
for(i=0,a='a';a<'z';a++,i++)
m_Text[i]=a;
for(i=0,a='A';a<'Z';a++,i++)
p_Text[i]=a;
for(i=0;i<26;i++)
{
if(m_Text[i] || p_Text[i]==x)
j=i+1;
}
return j;
}
bool M_or_P()
{
int a;
a=rand()%10+1;
if(a%2==0)
return true;
else
return false;
}
char char_Value(int x)
{
int i;
bool k;
char a,j;
char m_Text[26],p_Text[26];
j=0;
for(i=0,a='a';a<'z';a++,i++)
m_Text[i]=a;
for(i=0,a='A';a<'Z';a++,i++)
p_Text[i]=a;
k=M_or_P();
if(k)
{
j=m_Text[x];
}
else
{
j=p_Text[x];
}
return j;
}
public:
ciphere_Text(char *date)
{
int i,random_Value;
size_Text=strlen(date);
int *temp_Array=new int[size_Text];
c_Text=new char[size_Text];
random_Value=1+rand()%25;
for(i=0;i<size_Text;i++)
{
temp_Array[i]=result_Josephus(date[i],random_Value);
}
for(i=0;i<size_Text;i++)
{
c_Text[i]=char_Value(temp_Array[i]);
}
}
char *give_Result()
{
return c_Text;
}
~ciphere_Text()
{
delete c_Text;
}
};
środa, 16 stycznia 2019
niedziela, 6 stycznia 2019
Development of the Floyd algorithm (class C++)
class Floyd_Alg
{
private:
int m_size;
int m_min;
int m_max;
int m_use;
int **floyd_Array,**temp_Array;
int min_T(int a1, int a2);
public:
Floyd_Alg(int size, int min, int max, int use);
void init_Array();
void init_Floyd();
void Report();
~Floyd_Alg();
};
int Floyd_Alg::min_T(int a1, int a2)
{
int result;
if(a1<=a2)
result=a1;
else
result=a2;
return result;
}
Floyd_Alg::Floyd_Alg(int size, int min, int max, int use)
{
int i;
m_size=size;
m_min=min;
m_max=max;
m_use=use;
floyd_Array=new int*[m_size];
temp_Array=new int*[m_size];
for(i=0;i<m_size;i++)
{
floyd_Array[i]=new int[m_size];
temp_Array[i]=new int[m_size];
}
}
void Floyd_Alg::init_Array()
{
int i,j,k1,k2;
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
temp_Array[i][j]=-1;
floyd_Array[i][j]=-1;
}
}
i=0;
do
{
do
{
k1=rand()%m_size;
k2=rand()%m_size;
}while(temp_Array[k1][k2]!=-1);
temp_Array[k1][k2]=0;
++i;
}while(i<m_use);
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
if(temp_Array[i][j]==0)
floyd_Array[i][j]=m_min+rand()%(m_max-m_min);
}
}
}
void Floyd_Alg::init_Floyd()
{
int i,j,k;
for(i=0;i<m_size;i++)
for(j=0;j<m_size;j++)
for(k=0;k<m_size;k++)
floyd_Array[j][k]=min_T(floyd_Array[j][k],floyd_Array[j][k]+floyd_Array[i][k]);
}
void Floyd_Alg::Report()
{
int i,j;
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
if(floyd_Array[i][j]==-1)
cout<<i<<"*---->>"<<j<<"[not possible]\n";
else if(i!=j)
cout<<i<<"*---->>"<<j<<"="<<floyd_Array[i][j]<<endl;
}
}
}
Floyd_Alg::~Floyd_Alg()
{
int i;
for(i=0;i<m_size;i++)
{
delete[] floyd_Array[i];
delete[] temp_Array[i];
}
delete [] floyd_Array;
delete [] temp_Array;
}
{
private:
int m_size;
int m_min;
int m_max;
int m_use;
int **floyd_Array,**temp_Array;
int min_T(int a1, int a2);
public:
Floyd_Alg(int size, int min, int max, int use);
void init_Array();
void init_Floyd();
void Report();
~Floyd_Alg();
};
int Floyd_Alg::min_T(int a1, int a2)
{
int result;
if(a1<=a2)
result=a1;
else
result=a2;
return result;
}
Floyd_Alg::Floyd_Alg(int size, int min, int max, int use)
{
int i;
m_size=size;
m_min=min;
m_max=max;
m_use=use;
floyd_Array=new int*[m_size];
temp_Array=new int*[m_size];
for(i=0;i<m_size;i++)
{
floyd_Array[i]=new int[m_size];
temp_Array[i]=new int[m_size];
}
}
void Floyd_Alg::init_Array()
{
int i,j,k1,k2;
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
temp_Array[i][j]=-1;
floyd_Array[i][j]=-1;
}
}
i=0;
do
{
do
{
k1=rand()%m_size;
k2=rand()%m_size;
}while(temp_Array[k1][k2]!=-1);
temp_Array[k1][k2]=0;
++i;
}while(i<m_use);
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
if(temp_Array[i][j]==0)
floyd_Array[i][j]=m_min+rand()%(m_max-m_min);
}
}
}
void Floyd_Alg::init_Floyd()
{
int i,j,k;
for(i=0;i<m_size;i++)
for(j=0;j<m_size;j++)
for(k=0;k<m_size;k++)
floyd_Array[j][k]=min_T(floyd_Array[j][k],floyd_Array[j][k]+floyd_Array[i][k]);
}
void Floyd_Alg::Report()
{
int i,j;
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
if(floyd_Array[i][j]==-1)
cout<<i<<"*---->>"<<j<<"[not possible]\n";
else if(i!=j)
cout<<i<<"*---->>"<<j<<"="<<floyd_Array[i][j]<<endl;
}
}
}
Floyd_Alg::~Floyd_Alg()
{
int i;
for(i=0;i<m_size;i++)
{
delete[] floyd_Array[i];
delete[] temp_Array[i];
}
delete [] floyd_Array;
delete [] temp_Array;
}
środa, 2 stycznia 2019
System statistic (class C++ (g++))
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <linux/kernel.h>
using namespace std;
class system_Statistic
{
private:
struct utsname uname_Info;
struct sysinfo sys_Info;
struct rusage cpu_Times;
char *sysname;
char *version;
char *machine;
float free_RAM;
int process;
float total_RAM;
int time_Process1;
int time_Process2;
public:
system_Statistic()
{
uname(&uname_Info);
sysinfo(&sys_Info);
getrusage(RUSAGE_SELF,&cpu_Times);
sysname=uname_Info.sysname;
version=uname_Info.version;
machine=uname_Info.machine;
process=sys_Info.procs;
free_RAM=sys_Info.freeram/(1024.0*1024.0);
total_RAM=sys_Info.totalram/(1024.0*1024.0);
time_Process1=cpu_Times.ru_utime.tv_sec;
time_Process2=cpu_Times.ru_utime.tv_usec;
}
void Report()
{
cout<<"Sysname: "<<sysname<<endl;
cout<<"Version: "<<version<<endl;
cout<<"Machine: "<<machine<<endl;
cout<<"Number of processes: "<<process<<endl;
cout<<"Total RAM: "<<total_RAM<<endl;
cout<<"Free RAM: "<<free_RAM<<endl;
cout<<"Time of the process1: "<<time_Process1<<endl;
cout<<"Time of the process2: "<<time_Process2<<endl;
}
};
int main(int argc, char **argv)
{
system_Statistic Info;
Info.Report();
return 0;
}
#include <stdio.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <linux/kernel.h>
using namespace std;
class system_Statistic
{
private:
struct utsname uname_Info;
struct sysinfo sys_Info;
struct rusage cpu_Times;
char *sysname;
char *version;
char *machine;
float free_RAM;
int process;
float total_RAM;
int time_Process1;
int time_Process2;
public:
system_Statistic()
{
uname(&uname_Info);
sysinfo(&sys_Info);
getrusage(RUSAGE_SELF,&cpu_Times);
sysname=uname_Info.sysname;
version=uname_Info.version;
machine=uname_Info.machine;
process=sys_Info.procs;
free_RAM=sys_Info.freeram/(1024.0*1024.0);
total_RAM=sys_Info.totalram/(1024.0*1024.0);
time_Process1=cpu_Times.ru_utime.tv_sec;
time_Process2=cpu_Times.ru_utime.tv_usec;
}
void Report()
{
cout<<"Sysname: "<<sysname<<endl;
cout<<"Version: "<<version<<endl;
cout<<"Machine: "<<machine<<endl;
cout<<"Number of processes: "<<process<<endl;
cout<<"Total RAM: "<<total_RAM<<endl;
cout<<"Free RAM: "<<free_RAM<<endl;
cout<<"Time of the process1: "<<time_Process1<<endl;
cout<<"Time of the process2: "<<time_Process2<<endl;
}
};
int main(int argc, char **argv)
{
system_Statistic Info;
Info.Report();
return 0;
}
czwartek, 27 grudnia 2018
Reading the parameter of the file (class C++)
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
class read_Value
{
private:
float float_Result;
char *text_Result;
char *file_Name;
char *dest_Name;
bool test_Buffer(size_t s_read, char *buff);
bool is_Null(char *buff);
float read_float_Value(char *file_Name, char *float_Value);
char* read_text_Value(char *file_Name,char *text_Value);
public:
read_Value(char *file,char *ex_result);
char *write_Text();
float write_Float();
};
read_Value::read_Value(char *file,char *ex_result)
{
file_Name=file;
dest_Name=ex_result;
}
bool read_Value::test_Buffer(size_t s_read, char *buff)
{
if(s_read==0 || s_read==sizeof(buff))
return true;
else
return false;
}
bool read_Value::is_Null(char *buff)
{
if(buff==NULL)
return true;
else
return false;
}
char* read_Value::read_text_Value(char *file_Name,char *text_Value)
{
char *result;
char temp[2048],*match_buff,*sscan_buff;
strcpy(sscan_buff,text_Value);
strcat(sscan_buff," : %s");
size_t byt_read;
FILE *f_File;
f_File=fopen(file_Name,"r");
byt_read=fread(temp,1,sizeof(temp),f_File);
fclose(f_File);
if(test_Buffer(byt_read,temp))
return 0;
temp[byt_read]='\0';
match_buff=strstr(temp,text_Value);
if(is_Null(match_buff))
return 0;
sscanf(match_buff,sscan_buff,result);
return result;
}
float read_Value::read_float_Value(char *file_Name, char *float_Value)
{
float result;
char temp[2048],*match_buff,*sscan_buff;
strcpy(sscan_buff,float_Value);
strcat(sscan_buff," : %f");
size_t byt_read;
FILE *f_File;
f_File=fopen(file_Name,"r");
byt_read=fread(temp,1,sizeof(temp),f_File);
fclose(f_File);
if(test_Buffer(byt_read,temp))
return 0;
temp[byt_read]='\0';
match_buff=strstr(temp,float_Value);
if(is_Null(match_buff))
return 0;
sscanf(match_buff,sscan_buff,&result);
return result;
}
char * read_Value::write_Text()
{
text_Result=read_text_Value(file_Name,dest_Name);
return text_Result;
}
float read_Value::write_Float()
{
float_Result=read_float_Value(file_Name,dest_Name);
return float_Result;
}
int main(int argc, char *argv[])
{
char *file_Char;
float file_Float;
read_Value r_Value("C:\Nowy folder\test_File.txt","test");
file_Char=r_Value.write_Text();
cout<<file_Char<<endl;
read_Value f_Value("C:\Nowy folder\float_File.txt","test");
file_Float=f_Value.write_Float();
cout<<file_Float<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
class read_Value
{
private:
float float_Result;
char *text_Result;
char *file_Name;
char *dest_Name;
bool test_Buffer(size_t s_read, char *buff);
bool is_Null(char *buff);
float read_float_Value(char *file_Name, char *float_Value);
char* read_text_Value(char *file_Name,char *text_Value);
public:
read_Value(char *file,char *ex_result);
char *write_Text();
float write_Float();
};
read_Value::read_Value(char *file,char *ex_result)
{
file_Name=file;
dest_Name=ex_result;
}
bool read_Value::test_Buffer(size_t s_read, char *buff)
{
if(s_read==0 || s_read==sizeof(buff))
return true;
else
return false;
}
bool read_Value::is_Null(char *buff)
{
if(buff==NULL)
return true;
else
return false;
}
char* read_Value::read_text_Value(char *file_Name,char *text_Value)
{
char *result;
char temp[2048],*match_buff,*sscan_buff;
strcpy(sscan_buff,text_Value);
strcat(sscan_buff," : %s");
size_t byt_read;
FILE *f_File;
f_File=fopen(file_Name,"r");
byt_read=fread(temp,1,sizeof(temp),f_File);
fclose(f_File);
if(test_Buffer(byt_read,temp))
return 0;
temp[byt_read]='\0';
match_buff=strstr(temp,text_Value);
if(is_Null(match_buff))
return 0;
sscanf(match_buff,sscan_buff,result);
return result;
}
float read_Value::read_float_Value(char *file_Name, char *float_Value)
{
float result;
char temp[2048],*match_buff,*sscan_buff;
strcpy(sscan_buff,float_Value);
strcat(sscan_buff," : %f");
size_t byt_read;
FILE *f_File;
f_File=fopen(file_Name,"r");
byt_read=fread(temp,1,sizeof(temp),f_File);
fclose(f_File);
if(test_Buffer(byt_read,temp))
return 0;
temp[byt_read]='\0';
match_buff=strstr(temp,float_Value);
if(is_Null(match_buff))
return 0;
sscanf(match_buff,sscan_buff,&result);
return result;
}
char * read_Value::write_Text()
{
text_Result=read_text_Value(file_Name,dest_Name);
return text_Result;
}
float read_Value::write_Float()
{
float_Result=read_float_Value(file_Name,dest_Name);
return float_Result;
}
int main(int argc, char *argv[])
{
char *file_Char;
float file_Float;
read_Value r_Value("C:\Nowy folder\test_File.txt","test");
file_Char=r_Value.write_Text();
cout<<file_Char<<endl;
read_Value f_Value("C:\Nowy folder\float_File.txt","test");
file_Float=f_Value.write_Float();
cout<<file_Float<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
sobota, 22 grudnia 2018
Use /proc/meminfo (gcc)
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
int i;
char *file;
char end;
FILE *m_File;
char buffer_F[5][1024];
size_t read_Buff[5];
unsigned int mem_Total,mem_Free,mem_Shared,swap_Total,swap_Free;
char *info_mem_Total,*info_mem_Free,*info_mem_Shared,*info_swap_Total,
*info_swap_Free;
file="/proc/meminfo";
end='\0';
m_File=fopen(file,"r");
for(i=0;i<5;i++)
{
read_Buff[i]=fread(buffer_F[i],1,sizeof(buffer_F[i]),m_File);
}
fclose(m_File);
for(i=0;i<5;i++)
{
buffer_F[i][read_Buff[i]]=end;
}
info_mem_Total=strstr(buffer_F[0],"MemTotal");
sscanf(info_mem_Total,"MemTotal : %u",&mem_Total);
info_mem_Free=strstr(buffer_F[1],"MemFree");
sscanf(info_mem_Free,"MemFree : %u",&mem_Free);
info_mem_Shared=strstr(buffer_F[2],"MemShared");
sscanf(info_mem_Shared,"MemShared : %u",&mem_Shared);
info_swap_Total=strstr(buffer_F[3],"SwapTotal");
sscanf(info_swap_Total,"SwapTotal: %u",&swap_Total);
info_swap_Free=strstr(buffer_F[4],"SwapFree");
sscanf(info_swap_Free,"SwapFree: %u",&swap_Free);
printf("\nMemTotal: %u",mem_Total);
printf("\nMemFree : %u",mem_Free);
printf("\nMemShared : %u",mem_Shared);
printf("\nSwapTotal: %u",swap_Total);
printf("\nswap_Free: %u",swap_Free);
return 0;
}
#include <string.h>
int main(int argc, char **argv)
{
int i;
char *file;
char end;
FILE *m_File;
char buffer_F[5][1024];
size_t read_Buff[5];
unsigned int mem_Total,mem_Free,mem_Shared,swap_Total,swap_Free;
char *info_mem_Total,*info_mem_Free,*info_mem_Shared,*info_swap_Total,
*info_swap_Free;
file="/proc/meminfo";
end='\0';
m_File=fopen(file,"r");
for(i=0;i<5;i++)
{
read_Buff[i]=fread(buffer_F[i],1,sizeof(buffer_F[i]),m_File);
}
fclose(m_File);
for(i=0;i<5;i++)
{
buffer_F[i][read_Buff[i]]=end;
}
info_mem_Total=strstr(buffer_F[0],"MemTotal");
sscanf(info_mem_Total,"MemTotal : %u",&mem_Total);
info_mem_Free=strstr(buffer_F[1],"MemFree");
sscanf(info_mem_Free,"MemFree : %u",&mem_Free);
info_mem_Shared=strstr(buffer_F[2],"MemShared");
sscanf(info_mem_Shared,"MemShared : %u",&mem_Shared);
info_swap_Total=strstr(buffer_F[3],"SwapTotal");
sscanf(info_swap_Total,"SwapTotal: %u",&swap_Total);
info_swap_Free=strstr(buffer_F[4],"SwapFree");
sscanf(info_swap_Free,"SwapFree: %u",&swap_Free);
printf("\nMemTotal: %u",mem_Total);
printf("\nMemFree : %u",mem_Free);
printf("\nMemShared : %u",mem_Shared);
printf("\nSwapTotal: %u",swap_Total);
printf("\nswap_Free: %u",swap_Free);
return 0;
}
czwartek, 20 grudnia 2018
Use "/proc/cpuinfo" C++ (g++)
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
class CPU
{
private:
FILE *fp1,*fp2,*fp3;
char buff1[2048],buff2[2048],buff3[2048];
char *conv1,*conv2,*conv3,*name;
float speed_cpu,memory_cache;
size_t file1_read,file2_read,file3_read;
public:
void open_Files();
void name_Info();
void speed_Info();
void cache_size_Info();
};
void CPU::open_Files()
{
fp1=fopen("/proc/cpuinfo","r");
file1_read=fread(buff1,1,sizeof(buff1),fp1);
fclose(fp1);
fp2=fopen("/proc/cpuinfo","r");
file2_read=fread(buff2,1,sizeof(buff2),fp2);
fclose(fp2);
fp3=fopen("/proc/cpuinfo","r");
file3_read=fread(buff3,1,sizeof(buff3),fp3);
fclose(fp3);
buff1[file1_read]='\0';
buff2[file2_read]='\0';
buff3[file3_read]='\0';
}
void CPU::name_Info()
{
conv1=strstr(buff1,"model name");
sscanf(conv1,"model name : %s",name);
cout<<"Model name: "<<name<<endl;
}
void CPU::speed_Info()
{
conv2=strstr(buff2,"cpu MHz");
sscanf(conv2,"cpu MHz : %f",&speed_cpu);
cout<<"cpu MHz: "<<speed_cpu<<endl;
}
void CPU::cache_size_Info()
{
conv3=strstr(buff3,"cache size");
sscanf(conv3,"cache size: %f",&memory_cache);
cout<<"Cache size (KB): "<<memory_cache<<endl;
}
int main(int argc, char **argv)
{
CPU *info_CPU=new class CPU;
info_CPU->open_Files();
info_CPU->name_Info();
info_CPU->speed_Info();
info_CPU->cache_size_Info();
delete info_CPU;
return 0;
}
#include <string.h>
#include <stdio.h>
using namespace std;
class CPU
{
private:
FILE *fp1,*fp2,*fp3;
char buff1[2048],buff2[2048],buff3[2048];
char *conv1,*conv2,*conv3,*name;
float speed_cpu,memory_cache;
size_t file1_read,file2_read,file3_read;
public:
void open_Files();
void name_Info();
void speed_Info();
void cache_size_Info();
};
void CPU::open_Files()
{
fp1=fopen("/proc/cpuinfo","r");
file1_read=fread(buff1,1,sizeof(buff1),fp1);
fclose(fp1);
fp2=fopen("/proc/cpuinfo","r");
file2_read=fread(buff2,1,sizeof(buff2),fp2);
fclose(fp2);
fp3=fopen("/proc/cpuinfo","r");
file3_read=fread(buff3,1,sizeof(buff3),fp3);
fclose(fp3);
buff1[file1_read]='\0';
buff2[file2_read]='\0';
buff3[file3_read]='\0';
}
void CPU::name_Info()
{
conv1=strstr(buff1,"model name");
sscanf(conv1,"model name : %s",name);
cout<<"Model name: "<<name<<endl;
}
void CPU::speed_Info()
{
conv2=strstr(buff2,"cpu MHz");
sscanf(conv2,"cpu MHz : %f",&speed_cpu);
cout<<"cpu MHz: "<<speed_cpu<<endl;
}
void CPU::cache_size_Info()
{
conv3=strstr(buff3,"cache size");
sscanf(conv3,"cache size: %f",&memory_cache);
cout<<"Cache size (KB): "<<memory_cache<<endl;
}
int main(int argc, char **argv)
{
CPU *info_CPU=new class CPU;
info_CPU->open_Files();
info_CPU->name_Info();
info_CPU->speed_Info();
info_CPU->cache_size_Info();
delete info_CPU;
return 0;
}
niedziela, 16 grudnia 2018
Greedy algorithm. Creating nad selected sum and sorting from prime numbers.
private: // User declarations
void __fastcall i_Sort(int *tab, int size);
void __fastcall m_Sort(int *tab, int size);
bool __fastcall is_First(int value);
void __fastcall is_Sum(int *tab, int size,int value);
int *tab_First,**data_First1,**data_First2,*test_Values;
void __fastcall init_Arrays();
void __fastcall destroy_Arrays();
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
srand(time(NULL));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::i_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;
}
}
void __fastcall TForm1::m_Sort(int *tab, int size)
{
int i,j,k;
for(i=1;i<size;i++)
for(j=size-1;j>=i;j--)
if(tab[j]>tab[j-1])
{
k=tab[j-1];
tab[j-1]=tab[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::is_Sum(int *tab, int size,int value)
{
int i,j,sum;
do
{
sum=0;
for(i=0;i<size;i++)
{
j=rand()%500;
sum+=tab_First[j];
tab[i]=tab_First[j];
}
}while(sum!=value);
}
void __fastcall TForm1::init_Arrays()
{
int i,j;
tab_First=new int[100];
test_Values=new int[10];
data_First1=new int *[10];
data_First2=new int *[10];
for(i=0;i<10;i++)
{
data_First1[i]=new int[10];
data_First2[i]=new int[10];
}
i=0;j=2;
do
{
if(is_First(j))
{
tab_First[i]=j;
++i;
}
++j;
}while(i<100);
}
void __fastcall TForm1::destroy_Arrays()
{
int i;
delete tab_First;
delete test_Values;
for(i=0;i<10;i++)
{
delete [] data_First2[i];
delete [] data_First1[i];
}
delete data_First1;
delete data_First2;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
init_Arrays();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i,j,min,max;
min=800;
max=2000;
for(i=0;i<10;i++)
{
test_Values[i]=min+rand()%(max-min);
StringGrid3->Cells[0][i]=IntToStr(test_Values[i]);
}
for(i=0;i<10;i++)
{
is_Sum(data_First1[i],10,test_Values[i]);
is_Sum(data_First2[i],10,test_Values[i]);
}
for(i=0;i<10;i++)
{
i_Sort(data_First1[i],10);
m_Sort(data_First2[i],10);
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
StringGrid1->Cells[i][j]=IntToStr(data_First1[j][i]);
StringGrid2->Cells[i][j]=IntToStr(data_First2[j][i]);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
destroy_Arrays();
Close();
}
Subskrybuj:
Posty (Atom)
