#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#define min 10
#define max 20
using namespace std;
class Replace_array
{
private:
int size_array;
int *array1;
int *array2;
int *array3;
public:
Replace_array(int *arr1,int *arr2, int size);
~Replace_array();
};
Replace_array::Replace_array(int *arr1, int *arr2, int size)
{
array1=arr1;
array2=arr2;
size_array=size;
array3=new int[size_array];
int i;
for(i=0;i<size_array;i++)
{
array3[i]=array1[i];
array1[i]=array2[i];
array2[i]=array3[i];
}
}
Replace_array::~Replace_array()
{
delete array3;
}
void Init_random()
{
srand(time(NULL));
}
int main(int argc, char** argv)
{
Init_random();
int my_size_array,*my_array1,*my_array2,i;
my_size_array=max-rand()%min;
my_array1=new int[my_size_array];
my_array2=new int[my_size_array];
for(i=0;i<my_size_array;i++)
{
my_array1[i]=rand()%100;
my_array2[i]=rand()%100;
}
cout<<"Before replace array: \n";
cout<<"Array1: ";
for(i=0;i<my_size_array;i++)
{
cout<<my_array1[i]<<" ";
}
cout<<endl;
cout<<"Array2: ";
for(i=0;i<my_size_array;i++)
{
cout<<my_array2[i]<<" ";
}
cout<<endl;
cout<<"After replace array: \n";
Replace_array My_replace(my_array1,my_array2,my_size_array);
cout<<"Array1: ";
for(i=0;i<my_size_array;i++)
{
cout<<my_array1[i]<<" ";
}
cout<<endl;
cout<<"Array2: ";
for(i=0;i<my_size_array;i++)
{
cout<<my_array2[i]<<" ";
}
delete my_array2;
delete my_array1;
return 0;
}
Brak komentarzy:
Prześlij komentarz