axeefectushka

Untitled

Jan 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. class first {
  8. protected:
  9.     int *arr;
  10.     int sizeArr;
  11. public:
  12.     first(int size) : sizeArr(size) {
  13.         arr = new int[size];
  14.     }
  15.     first() {
  16.         arr = NULL;
  17.         sizeArr = 0;
  18.     }
  19.     virtual int task() {
  20.         int sum = 0;
  21.         for (int i = 0; i<sizeArr; i++) {
  22.             if (i >= sizeArr)
  23.             {
  24.                 RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL);
  25.             }
  26.             sum += arr[i];
  27.         }
  28.         return sum;
  29.     }
  30.     virtual void InputArray() {
  31.         cout << "Input elements: ";
  32.         for (int i = 0; i<sizeArr; i++) {
  33.             cin >> arr[i];
  34.         }
  35.     }
  36.     ~first() {
  37.         delete[]arr;
  38.     }
  39. };
  40.  
  41. class second : public first {
  42. public:
  43.     second(int sizeArrHui) : first(sizeArrHui)
  44.     {}
  45.     int task() {
  46.         int mult = 1;
  47.         for (int i = 0; i<sizeArr; i++) {
  48.             if (i >= sizeArr)RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL);
  49.             mult *= arr[i];
  50.         }
  51.         return mult;
  52.     }
  53. };
  54.  
  55. int main()
  56. {
  57.     first MAS1(1);
  58.     second MAS2(10);
  59.  
  60.     __try
  61.     {
  62.         MAS1.InputArray();
  63.         MAS2.InputArray();
  64.  
  65.         cout << "SUM OF 1ST ARRAY:" << MAS1.task() << endl;
  66.         cout << "MULT OF 2ND ARRAY:" << MAS2.task() << endl;
  67.     }
  68.     __except (EXCEPTION_EXECUTE_HANDLER)
  69.     {
  70.         if (GetExceptionCode() == EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
  71.         {
  72.             cout << "ERROR!" << endl;
  73.         }
  74.     }
  75.     return 0;
  76. }#include <stdio.h>
  77. #include <iostream>
  78. #include <windows.h>
  79.  
  80. using namespace std;
  81.  
  82. class first {
  83. protected:
  84.     int *arr;
  85.     int sizeArr;
  86. public:
  87.     first(int size) : sizeArr(size) {
  88.         arr = new int[size];
  89.     }
  90.     first() {
  91.         arr = NULL;
  92.         sizeArr = 0;
  93.     }
  94.     virtual int task() {
  95.         int sum = 0;
  96.         for (int i = 0; i<sizeArr; i++) {
  97.             if (i >= sizeArr)
  98.             {
  99.                 RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL);
  100.             }
  101.             sum += arr[i];
  102.         }
  103.         return sum;
  104.     }
  105.      void InputArray() {
  106.         cout << "Input elements: ";
  107.         for (int i = 0; i<sizeArr; i++) {
  108.             cin >> arr[i];
  109.         }
  110.     }
  111.     ~first() {
  112.         delete[]arr;
  113.     }
  114. };
  115.  
  116. class second : public first {
  117. public:
  118.     second(int sizeArrHui) : first(sizeArrHui)
  119.     {}
  120.     int task() {
  121.         int mult = 1;
  122.         for (int i = 0; i<sizeArr; i++) {
  123.             if (mult>INT_MAX)RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL);
  124.             mult *= arr[i];
  125.         }
  126.         return mult;
  127.     }
  128. };
  129.  
  130. int main()
  131. {
  132.     first MAS1(1);
  133.     second MAS2(10);
  134.  
  135.     __try
  136.     {
  137.         MAS1.InputArray();
  138.         MAS2.InputArray();
  139.  
  140.         cout << "SUM OF 1ST ARRAY:" << MAS1.task() << endl;
  141.         cout << "MULT OF 2ND ARRAY:" << MAS2.task() << endl;
  142.     }
  143.     __except (EXCEPTION_EXECUTE_HANDLER)
  144.     {
  145.         if (GetExceptionCode() == EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
  146.         {
  147.             cout << "ERROR!" << endl;
  148.         }
  149.     }
  150.     return 0;
  151. }
Add Comment
Please, Sign In to add comment