Data in files: table_SQRT.txt and REPORT.txt
#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;
}
Brak komentarzy:
Prześlij komentarz