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];
- }
- 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;
- }
- virtual void InputArray() {
- cout << "Input elements: ";
- for (int i = 0; i<sizeArr; i++) {
- cin >> arr[i];
- }
- }
- ~first() {
- delete[]arr;
- }
- };
- class second : public first {
- public:
- second(int sizeArrHui) : first(sizeArrHui)
- {}
- int task() {
- int mult = 1;
- for (int i = 0; i<sizeArr; i++) {
- if (i >= sizeArr)RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL);
- mult *= arr[i];
- }
- return mult;
- }
- };
- int main()
- {
- first MAS1(1);
- second MAS2(10);
- __try
- {
- MAS1.InputArray();
- MAS2.InputArray();
- cout << "SUM OF 1ST ARRAY:" << MAS1.task() << endl;
- cout << "MULT OF 2ND ARRAY:" << MAS2.task() << endl;
- }
- __except (EXCEPTION_EXECUTE_HANDLER)
- {
- if (GetExceptionCode() == EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
- {
- cout << "ERROR!" << endl;
- }
- }
- return 0;
- }#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];
- }
- 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;
- }
- void InputArray() {
- cout << "Input elements: ";
- for (int i = 0; i<sizeArr; i++) {
- cin >> arr[i];
- }
- }
- ~first() {
- delete[]arr;
- }
- };
- class second : public first {
- public:
- second(int sizeArrHui) : first(sizeArrHui)
- {}
- int task() {
- int mult = 1;
- for (int i = 0; i<sizeArr; i++) {
- if (mult>INT_MAX)RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL);
- mult *= arr[i];
- }
- return mult;
- }
- };
- int main()
- {
- first MAS1(1);
- second MAS2(10);
- __try
- {
- MAS1.InputArray();
- MAS2.InputArray();
- cout << "SUM OF 1ST ARRAY:" << MAS1.task() << endl;
- cout << "MULT OF 2ND ARRAY:" << MAS2.task() << endl;
- }
- __except (EXCEPTION_EXECUTE_HANDLER)
- {
- if (GetExceptionCode() == EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
- {
- cout << "ERROR!" << endl;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment