Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- template<class T>
- class division
- {
- T a,b,c;
- public:
- void divide();
- void input()
- {
- cout<<"Enter the two numbers: ";
- cin>> a >> b;
- }
- };
- template<class T>
- void division<T>::divide()
- {
- try
- {
- if(b==0)
- throw b;
- else
- c=a/b;
- cout<<c;
- }
- catch(T b)
- {
- cout<<"Error";
- }
- }
- int main()
- {
- division<int>d1;
- d1.input();
- d1.divide();
- division<float>d2;
- d2.input();
- d2.divide();
- }
Add Comment
Please, Sign In to add comment