Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class arr
- {
- private:
- int* a;
- int len;
- public:
- arr(int Len) { a = new int[Len], len = Len; }
- arr(int Len, int x)
- {
- a = new int[Len], len = Len;
- for (int i = 0; i < Len; i++) a[i] = x;
- }
- ~arr() { delete[] a; cout << "Array was deleted.\n"; }
- void input() { for (int i = 0; i < len; i++) cin >> a[i]; }
- void output() { for (int i = 0; i < len; i++) cout << a[i] << " "; cout << endl; }
- void e_o(int* e, int* o)
- {
- int l, r;
- *e = 0; *o = 0;
- do {
- cin >> r >> l;
- if (l % 2 != 0 || r % 2 != 0) cout << "Indexes must be positive and not go beyond the array. Try again.\n";
- } while (l % 2 != 0 || r % 2 != 0 || r >= len || l >= len || r < 0 || l<0);
- if (l > r) swap(l, r);
- for (int i = l; i <= r; i++)
- if (a[i] % 2) *o += 1;
- else *e += 1;
- }
- };
- int main(){
- int even, odd;
- arr A(7), B(5, 3);
- B.output();
- A.input();
- A.e_o(&even, &odd);
- cout << odd << " odd numbers and " << even << " even numbers are located between these indexes in the array.\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement