Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 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 size, 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.  
  41. int main()
  42. {
  43.     srand(time(0));
  44.     mas array(10, -100, 100);
  45.     array.out();
  46.     array.do_it();
  47.     array.out();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement