SHARE
TWEET

second

a guest Feb 21st, 2020 73 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. void 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.     DeleteElements(array, size);
  22.     Delete(array);
  23. }
  24.  
  25. int *CreateDynamic(int amount){
  26.      int *temp = new int[amount];
  27.     if(temp){
  28.         return temp;
  29.     }
  30. }
  31.  
  32. void Fill(int *array, int amount){
  33.     for(int i = 0; i < amount; i++){
  34.         *(array+i) = rand() % 100;
  35.     }
  36. }
  37.  
  38. void Out(int *array, int amount){
  39.     for(int i = 0; i < amount; i++){
  40.         cout << *(array+i) << " ";
  41.     }
  42.     cout << endl;
  43. }
  44.  
  45. void DeleteElements(int *array, int amount){
  46.     int count = 0;
  47.     for(int i = 0; i < amount; i++){
  48.         if(i % 2 == 1 ){
  49.             count++;
  50.         }
  51.     }
  52.    
  53.     int *temp = new int[count];
  54.     count = 0;
  55.    
  56.     for(int i = 0; i < amount; i++){
  57.         if(i % 2 == 1 ){
  58.             temp[count++] = array[i];
  59.            
  60.         }
  61.     }
  62.     Delete(array);
  63.     Out(temp, count);
  64.     Delete(temp);
  65. }
  66.  
  67. void Delete(int *array){
  68.     if(array){
  69.         delete[] array;
  70.         array = nullptr;
  71.     }
  72.     else{
  73.         cout << "Данный массив пуст!" << endl;
  74.         exit(1);
  75.     }
  76. }
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