Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Билет 5
- #include "stdafx.h"
- #include<iostream>
- #include <windows.h>
- using namespace std;
- class First {
- protected:
- int* array;
- int size;
- public:
- First() {
- cout << "size: ";
- cin >> size;
- cout << endl;
- array = new int[size];
- for (int i = 0; i < size; i++)
- {
- cout << "Element[" << i << "] = ";
- cin >> array[i];
- }
- }
- void summ()
- {
- int sum = 0;
- for (int i = 0; i < size; i++)
- {
- __try
- {
- if (INT_MAX - sum < array[i])
- {
- RaiseException(EXCEPTION_PRIV_INSTRUCTION, 0, 0, NULL);
- }
- sum += array[i];
- }
- __except (EXCEPTION_EXECUTE_HANDLER)
- {
- cout << "Error! Div by 0 or D<0" << endl;
- }
- }
- cout << sum << endl;
- }
- };
- class Second : public First
- {
- public:
- int multi()
- {
- int mul = 1;
- for (int i = 0; i < size; i++)
- {
- mul *= array[i];
- }
- cout << mul << endl;
- return mul;
- }
- };
- int main()
- {
- First o;
- try
- {
- o.summ();
- }
- catch (int a)
- {
- cout << "error #" << a << endl;
- }
- Second op;
- op.multi();
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment