Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Base{
- protected:
- int x,y;
- public:
- void get()
- {
- cout<<"Enter two numebrs"<<endl;
- cin>>x>>y;
- }
- };
- class D_1 : public Base
- {
- public:
- void sum()
- {
- cout<<"sum is "<<x+y<<endl;
- }
- };
- class D_2 : public Base{
- public:
- void product()
- {
- cout<<"Product is "<<x*y<<endl;
- }
- };
- int main()
- {
- D_1 a;
- D_2 b;
- a.get();
- a.sum();
- b.get();
- b.product();
- return 0;
- }
- /*
- Output
- Enter two numebrs
- 4 4
- sum is 8
- Enter two numebrs
- 33 3
- Product is 99
- */
Advertisement
Add Comment
Please, Sign In to add comment