axeefectushka

Untitled

Jan 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. Билет 5
  2. #include "stdafx.h"
  3. #include<iostream>
  4. #include <windows.h>
  5. using namespace std;
  6.  
  7. class First {
  8. protected:
  9.     int* array;
  10.     int size;
  11. public:
  12.     First() {
  13.         cout << "size: ";
  14.         cin >> size;
  15.         cout << endl;
  16.         array = new int[size];
  17.         for (int i = 0; i < size; i++)
  18.         {
  19.             cout << "Element[" << i << "] = ";
  20.             cin >> array[i];
  21.         }
  22.     }
  23.     void summ()
  24.     {
  25.         int sum = 0;
  26.         for (int i = 0; i < size; i++)
  27.         {
  28.             __try
  29.             {
  30.                 if (INT_MAX - sum < array[i])
  31.                 {
  32.                     RaiseException(EXCEPTION_PRIV_INSTRUCTION, 0, 0, NULL);
  33.                 }
  34.                 sum += array[i];
  35.             }
  36.             __except (EXCEPTION_EXECUTE_HANDLER)
  37.             {
  38.                 cout << "Error! Div by 0 or D<0" << endl;
  39.             }
  40.         }
  41.         cout << sum << endl;
  42.     }
  43. };
  44.  
  45. class Second : public First
  46. {
  47. public:
  48.     int multi()
  49.     {
  50.         int mul = 1;
  51.         for (int i = 0; i < size; i++)
  52.         {
  53.             mul *= array[i];
  54.         }
  55.         cout << mul << endl;
  56.         return mul;
  57.     }
  58. };
  59.  
  60. int main()
  61. {
  62.     First o;
  63.     try
  64.     {
  65.         o.summ();
  66.     }
  67.     catch (int a)
  68.     {
  69.         cout << "error #" << a << endl;
  70.     }
  71.     Second op;
  72.     op.multi();
  73.     system("pause");
  74.     return 0;
  75. }
Add Comment
Please, Sign In to add comment