SHARE
TWEET

first

a guest Feb 21st, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int *CreateDynamic(int amount);
  8. void Fill(int *array, int amount);
  9. void Out(int *array, int amount);
  10. int *DeleteElements(int *array, int *amount);
  11. void Delete(int *array);
  12.  
  13. int main()
  14. {
  15.     srand(time(0));
  16.     setlocale(LC_ALL, "russian");
  17.     int size; cin >> size;
  18.     int *array = CreateDynamic(size);
  19.     Fill(array, size);
  20.     Out(array, size);
  21.     array = DeleteElements(array, &size);
  22.     Out(array, size);
  23.     Delete(array);
  24. }
  25.  
  26. int *CreateDynamic(int amount){
  27.      int *temp = new int[amount];
  28.     if(temp){
  29.         return temp;
  30.     }
  31. }
  32.  
  33. void Fill(int *array, int amount){
  34.     for(int i = 0; i < amount; i++){
  35.         *(array+i) = rand() % 100;
  36.     }
  37. }
  38.  
  39. void Out(int *array, int amount){
  40.     for(int i = 0; i < amount; i++){
  41.         cout << *(array+i) << " ";
  42.     }
  43.     cout << endl;
  44. }
  45.  
  46. int *DeleteElements(int *array, int *amount){
  47.     int count = 0;
  48.     for(int i = 0; i < *amount; i++){
  49.         if(i % 2 == 1 ){
  50.             count++;
  51.         }
  52.     }
  53.    
  54.     int *temp = new int[count];
  55.     count = 0;
  56.    
  57.     for(int i = 0; i < *amount; i++){
  58.         if(i % 2 == 1 ){
  59.             temp[count++] = array[i];
  60.            
  61.         }
  62.     }
  63.     Delete(array);
  64.     *amount = count;
  65.     return temp;
  66. }
  67.  
  68. void Delete(int *array){
  69.     if(array){
  70.         delete[] array;
  71.         array = nullptr;
  72.     }
  73.     else{
  74.         cout << "Данный массив пуст!" << endl;
  75.         exit(1);
  76.     }
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top