Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <windows.h>
  4. using namespace std;
  5.  
  6. class A
  7. {
  8. protected:
  9.     int a;
  10.     int b;
  11. public:
  12.     A(int aa,int bb):a(aa),b(bb) {}
  13.     ~A()
  14.     {
  15.         cout << "Деструктор А." << endl;
  16.     }
  17. };
  18.  
  19. class B :public A
  20. {
  21. public:
  22.     B(int aa,int bb):A(aa,bb) {}
  23.     void task ()
  24.     {
  25.         double c;
  26.         __try
  27.         {
  28.             if (b == 0)
  29.             {
  30.                 RaiseException(EXCEPTION_PRIV_INSTRUCTION, 0, 0, NULL);
  31.             }
  32.             c = a / b;
  33.             cout << "c= " << c << endl;
  34.         }
  35.         __except (EXCEPTION_EXECUTE_HANDLER)
  36.         {
  37.             cout << "Деление на ноль." << endl;
  38.         }
  39.     }
  40.     ~B()
  41.     {
  42.         cout << "Деструктор В." << endl;
  43.     }
  44. };
  45.  
  46. int main()
  47. {
  48.     setlocale(LC_ALL, "Russian");
  49.     B a(1, 0);
  50.     a.task();
  51.     B b(4, 2);
  52.     b.task();
  53.     system("pause");
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement