Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. class mas {
  8. public:
  9.     int * data;
  10.     int size;
  11.  
  12.     mas(int msize, int lower, int upper) {
  13.         data = new int[size];
  14.         this->size = size;
  15.  
  16.         for (int i = 0; i < size; i++) {
  17.             data[i] = (rand() % (upper - lower + 1)) + lower;
  18.         }
  19.     }
  20.  
  21.     ~mas() {
  22.         delete[] data;
  23.     }
  24.  
  25.     void out() {
  26.         for (int i = 0; i < size; i++) {
  27.             cout << data[i] << " ";
  28.         }
  29.         cout << endl;
  30.     }
  31.  
  32.     void do_it() {
  33.         for (int i = 1; i < size - 1; i++) {
  34.             if (data[i] % 2 == 0) {
  35.                 data[i] += data[0];
  36.             }
  37.         }
  38.     }
  39.  
  40.     void sort() {
  41.         for (int i = 0; i < this->size - 1; i++) {
  42.             for (int j = i + 1; j < this->size; j++) {
  43.                 if (this->data[i] > this->data[j]) {
  44.                     int temp = this->data[i];
  45.                     this->data[i] = this->data[j];
  46.                     this->data[j] = temp;
  47.                 }
  48.             }
  49.         }
  50.     }
  51. };
  52.  
  53. int main()
  54. {
  55.     srand(time(0));
  56.     mas array(10, -100, 100);
  57.     array.out();
  58.     array.do_it();
  59.     array.out();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement