#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <fcntl.h>
#define size 10
using namespace std;
int **tab;
int **which_position;
int *table_with_first;
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 init_random()
{
srand(time(NULL));
}
int main(int argc, char** argv)
{
int i,j,k,sum;
init_random();
table_with_first=new int[size];
i=0;
j=1;
do
{
if(is_first(j))
{
table_with_first[i]=j;
++i;
}
++j;
}while(i<size);
which_position=new int *[size];
tab=new int *[size];
for(i=0;i<size;i++)
{
tab[i]=new int[size];
which_position[i]=new int[size];
}
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
k=rand()%size;
tab[i][j]=table_with_first[k];
which_position[i][j]=k;
}
}
for(k=0;k<size;k++)
{
for(i=1;i<size;i++)
for(j=size-1;j>=i;j--)
if(tab[k][j]<tab[k][j-1])
{
int tmp1=tab[k][j-1];
tab[k][j-1]=tab[k][j];
tab[k][j]=tmp1;
}
}
for(k=0;k<size;k++)
{
for(i=1;i<size;i++)
for(j=size-1;j>=i;j--)
if(which_position[k][j]<which_position[k][j-1])
{
int tmp1=which_position[k][j-1];
which_position[k][j-1]=which_position[k][j];
which_position[k][j]=tmp1;
}
}
FILE *file1,*file2;
file1=fopen("my_first_in_array","wt");
file2=fopen("my_position_in_array","wt");
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
fprintf(file1,"%d ",tab[i][j]);
fprintf(file2,"%d ",which_position[i][j]);
}
fprintf(file1,"\n");
fprintf(file2,"\n");
}
fclose(file2);
fclose(file1);
delete table_with_first;
for(i=0;i<size;i++)
{
delete [] which_position[i];
delete [] tab[i];
}
delete []*which_position;
delete []*tab;
return 0;
}
#include <iostream>
#include <fstream>
#include <signal.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include <stdio.h>
#define megabyte 1024*1024
using namespace std;
class Info_system
{
private:
struct utsname my_uname;
struct sysinfo my_info;
FILE *my_file;
char *my_name;
double write_megabyte;
public:
Info_system(char* my_file_info)
{
sysinfo(&my_info);
uname(&my_uname);
my_name=my_file_info;
}
void write_to_FIle ()
{
my_file=fopen(my_name,"w");
fprintf(my_file,"%s\n","Total RAM:");
fprintf(my_file,"%d\n",(my_info.totalram/megabyte));
fprintf(my_file,"%s\n","Free RAM:");
fprintf(my_file,"%d\n",(my_info.freeram/megabyte));
fprintf(my_file,"%s\n","Shared RAM: ");
fprintf(my_file,"%d\n",(my_info.sharedram/megabyte));
fprintf(my_file,"%s\n","Buffer RAM:");
fprintf(my_file,"%d\n",(my_info.bufferram/megabyte));
fprintf(my_file,"%s\n","Total SWAP:");
fprintf(my_file,"%d\n",(my_info.totalswap/megabyte));
fprintf(my_file,"%s\n","Free SWAP: ");
fprintf(my_file,"%d\n",my_info.freeswap/megabyte);
fprintf(my_file,"%s\n","Short PROCS: ");
fprintf(my_file,"%d\n",my_info.procs);
fprintf(my_file,"%s\n",my_uname.sysname);
fprintf(my_file,"%s\n",my_uname.release);
fprintf(my_file,"%s\n",my_uname.version);
fprintf(my_file,"%s\n",my_uname.machine);
fclose(my_file);
}
void read_from_File()
{
my_file=fopen(my_name,"r");
char my_buffer[2048];
while(!feof(my_file) && !ferror(my_file)
&& fgets(my_buffer,sizeof(my_buffer),my_file)!=NULL)
fputs(my_buffer,stdout);
fclose(my_file);
}
};
int main(int argc, char** argv)
{
Info_system My_s("file_statistic");
My_s.write_to_FIle();
My_s.read_from_File();
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
void init_random()
{
srand(time(NULL));
}
void bubble_sort(int *array, int n)
{
int i,j,k;
for(i=1;i<n;i++)
for(j=n-1;j>=i;j--)
if(array[j]<array[j-1])
{
k=array[j-1];
array[j-1]=array[j];
array[j]=k;
}
}
int main(int argc, char** argv)
{
int whole,how_many_numbers,how_many_reps;
int *my_numbers_drawn,*temp_whole;
int **all_numbers,**temp_all_numbers;
init_random();
cout<<"Whole numbers lottery? - ";cin>>whole;
cout<<"How many numbers will random? ";cin>>how_many_numbers;
cout<<"How many reps? ";cin>>how_many_reps;
int i,j,k;
my_numbers_drawn=new int[how_many_numbers];
temp_whole=new int[whole];
all_numbers=new int *[how_many_numbers];
for(i=0;i<how_many_numbers;i++)
all_numbers[i]=new int[how_many_reps];
temp_all_numbers=new int *[how_many_reps];
for(i=0;i<how_many_reps;i++)
temp_all_numbers[i]=new int[whole];
for(i=0;i<whole;i++)
temp_whole[i]=0;
for(i=0;i<how_many_reps;i++)
for(j=0;j<whole;j++)
temp_all_numbers[i][j]=0;
i=0;
do{
do
{
j=rand()%whole;
}while(temp_whole[j]!=0);
temp_whole[j]=1;
my_numbers_drawn[i]=j+1;
++i;
}while(i<how_many_numbers);
i=0;
do
{
j=0;
do
{
do
{
k=rand()%whole;
}while(temp_all_numbers[i][k]!=0);
temp_all_numbers[i][k]=1;
all_numbers[i][j]=k+1;
++j;
}while(j<how_many_numbers);
++i;
}while(i<how_many_reps);
bubble_sort(my_numbers_drawn,how_many_numbers);
cout<<"My bet: ";
for(i=0;i<how_many_numbers;i++)
{
cout<<my_numbers_drawn[i]<<" ";
}
for(i=0;i<how_many_reps;i++)
{
bubble_sort(all_numbers[i],how_many_numbers);
}
cout<<"\nDraw bet:";
cout<<"\n\n";
for(i=0;i<how_many_reps;i++)
{
for(j=0;j<how_many_numbers;j++)
{
cout<<all_numbers[i][j]<<" ";
}
cout<<"\n";
}
for(i=0;i<how_many_numbers;i++)
delete [] temp_all_numbers[i];
delete [] *temp_all_numbers;
for(i=0;i<how_many_reps;i++)
delete [] all_numbers[i];
delete [] *all_numbers;
delete temp_whole;
delete my_numbers_drawn;
getch();
return 0;
}
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
using namespace std;
#define min_size_array 5
#define max_size_array 20
void init_random()
{
srand(time(NULL));
}
class My_sort
{
private:
int my_size;
int *my_array1;
int *my_array2;
int *my_array3;
public:
My_sort(int *array,int size)
{
my_size=size;
my_array1=new int[my_size];
my_array2=new int[my_size];
my_array3=new int[my_size];
int i;
for(i=0;i<my_size;i++)
{
my_array1[i]=array[i];
my_array2[i]=array[i];
my_array3[i]=array[i];
}
}
int growing_number(int i, int j)
{
return (i>j);
}
int decreasing_number(int i, int j)
{
return (i<j);
}
void replace(int *i, int *j)
{
int k;
k=*i;
*i=*j;
*j=k;
}
void sort_growing()
{
int i,j;
for(i=0;i<my_size;i++)
{
for(j=0;j<my_size-1;j++)
{
if(growing_number(my_array1[j],my_array1[j+1]))
replace(&my_array1[j],&my_array1[j+1]);
}
}
}
void sort_decr()
{
int i,j;
for(i=0;i<my_size;i++)
{
for(j=0;j<my_size-1;j++)
{
if(decreasing_number(my_array2[j],my_array2[j+1]))
replace(&my_array2[j],&my_array2[j+1]);
}
}
}
void print()
{
int i;
cout<<"Oryginal array : ";
for(i=0;i<my_size;i++)
{
cout<<my_array3[i]<<" ";
}
cout<<"\n";
cout<<"After decr: ";
for(i=0;i<my_size;i++)
{
cout<<my_array2[i]<<" ";
}
cout<<"\n";
cout<<"After incr: ";
for(i=0;i<my_size;i++)
{
cout<<my_array1[i]<<" ";
}
}
~My_sort()
{
delete my_array3;
delete my_array2;
delete my_array1;
}
};
int main(int argc, char** argv)
{
init_random();
int my_size_array,i;
my_size_array=min_size_array+rand()%(max_size_array-min_size_array);
int *my_array=new int[my_size_array];
for(i=0;i<my_size_array;i++)
my_array[i]=rand()%30;
My_sort M1_sort(my_array,my_size_array);
M1_sort.sort_growing();
M1_sort.sort_decr();
M1_sort.print();
delete my_array;
return 0;
}