nrk009

TEMPLATE AND TRYCATCH OOPS ASS 7

Oct 2nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. template<class T>
  4. class division
  5. {
  6.     T a,b,c;
  7.     public:
  8.     void divide();
  9.     void input()
  10.     {
  11.         cout<<"Enter the two numbers: ";
  12.         cin>> a >> b;
  13.     }
  14. };
  15. template<class T>
  16. void division<T>::divide()
  17. {
  18.     try
  19.     {
  20.         if(b==0)
  21.             throw b;
  22.         else
  23.             c=a/b;
  24.             cout<<c;
  25.     }
  26.     catch(T b)
  27.     {
  28.         cout<<"Error";
  29.     }
  30. }
  31.  
  32. int main()
  33. {
  34.     division<int>d1;
  35.     d1.input();
  36.     d1.divide();
  37.     division<float>d2;
  38.     d2.input();
  39.     d2.divide();
  40. }
Add Comment
Please, Sign In to add comment