Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <windows.h>
- using namespace std;
- class first {
- protected:
- int *arr;
- int sizeArr;
- public:
- first(int size) : sizeArr(size)
- {
- arr = new int[size];
- cout << "Input elements: ";
- for (int i = 0; i < sizeArr; i++)
- {
- cin >> arr[i];
- }
- }
- first()
- {
- arr = NULL;
- sizeArr = 0;
- }
- virtual int task()
- {
- int sum = 0;
- for (int i = 0; i < sizeArr; i++) {
- if (i >= sizeArr)
- {
- RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL);
- }
- sum += arr[i];
- }
- return sum;
- }
- ~first() {
- delete[]arr;
- }
- };
- class second : public first
- {
- public:
- second(int sizeArr) : first(sizeArr)
- {}
- int task()
- {
- int mult = 1;
- __try
- {
- for (int i = 0; i < sizeArr; i++)
- {
- if (mult > INT_MAX)
- RaiseException(EXCEPTION_PRIV_INSTRUCTION, 0, 0, NULL);
- mult *= arr[i];
- }
- }
- __except (EXCEPTION_EXECUTE_HANDLER)
- {
- if (GetExceptionCode() == EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
- {
- cout << "ERROR!" << endl;
- }
- }
- return mult;
- }
- };
- int main()
- {
- first mas1(5);
- second mas2(5);
- cout << "MULT OF 1 ARRAY:" << mas1.task() << endl;
- cout << "MULT OF 2 ARRAY:" << mas2.task() << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment