#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <math.h>
#include <fstream>
using namespace std;
#define MAX 1000
#define m_DOUBLE 30
#define m_KEYS 52
string keys[m_KEYS]={"q","w","e","r","t","y","o","p","a","s","d","f","g","h","j","k","l",
"z","x","c","v","b","n","m","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F",
"G","H","J","K","L","Z","X","C","V","B","N","M"};
string files[3]={"binary.txt","string.txt","statistic.txt"};
fstream file1,file2,file3;
string int_to_String(int value)
{
int i,j,l;
j=0;
string result=" ";
if(value<m_KEYS)
result=keys[value];
else
{
do
{
j+=m_KEYS;
result+=keys[m_KEYS];
}while(j<value);
l=(j-value);
result+=keys[l];
}
return result;
}
bool 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 Sort(int *tab, int size_T)
{
int i,j,k;
for(i=1;i<size_T;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
int sum_Array(int *tab, int size_T)
{
int i,sum;
sum=0;
for(i=0;i<size_T;i++)
sum+=tab[i];
return sum;
}
double aver_Array(int *tab, int size_T)
{
double aver;
aver=(1.0*sum_Array(tab,size_T))/(1.0*size_T);
return aver;
}
int *main_Tab;
int **doub_Tab;
int *sum_Tab;
string **base_Tab;
double *aver_Tab;
int main()
{
int i,j,k;
main_Tab=new int[MAX];
aver_Tab=new double[m_DOUBLE];
sum_Tab=new int[m_DOUBLE];
srand(time(NULL));
i=0;
j=2;
do
{
if(is_First(j))
{
main_Tab[i]=j;
++i;
}
++j;
}while(i<MAX);
doub_Tab=new int *[m_DOUBLE];
for(i=0;i<m_DOUBLE;i++)
doub_Tab[i]=new int[m_DOUBLE];
base_Tab=new string *[m_DOUBLE];
for(i=0;i<m_DOUBLE;i++)
base_Tab[i]=new string[m_DOUBLE];
for(i=0;i<m_DOUBLE;i++)
{
for(j=0;j<m_DOUBLE;j++)
{
k=rand()%MAX;
doub_Tab[i][j]=main_Tab[k];
}
}
for(i=0;i<m_DOUBLE;i++)
{
Sort(doub_Tab[i],m_DOUBLE);
}
for(i=0;i<m_DOUBLE;i++)
{
aver_Tab[i]=aver_Array(doub_Tab[i],m_DOUBLE);
}
for(i=0;i<m_DOUBLE;i++)
{
for(j=0;j<m_DOUBLE;j++)
{
base_Tab[i][j]=int_to_String(doub_Tab[i][j]);
}
}
file1.open(files[0].c_str(),ios::in);
if(file1.good())
{
for(i=0;i<m_DOUBLE;i++)
{
for(j=0;j<m_DOUBLE;j++)
{
file1<<doub_Tab[i][j]<<", ";
file1.flush();
}
}
file1.close();
}
file2.open(files[1].c_str(),ios::in);
if(file2.good())
{
for(i=0;i<m_DOUBLE;i++)
{
for(j=0;j<m_DOUBLE;j++)
{
file2<<base_Tab[i][j]<<", ";
file2.flush();
}
}
file2.close();
}
file3.open(files[2].c_str(),ios::in);
if(file3.good())
{
for(i=0;i<m_DOUBLE;i++)
{
file3<<sum_Tab[i]<<" - "<<aver_Tab[i];
file3.flush();
}
file3.close();
}
for(i=0;i<m_DOUBLE;i++)
delete [] doub_Tab[i];
delete [] doub_Tab;
for(i=0;i<m_DOUBLE;i++)
delete [] base_Tab[i];
delete [] base_Tab;
delete aver_Tab;
delete main_Tab;
delete sum_Tab;
getch();
return 0;
}
Brak komentarzy:
Prześlij komentarz