Created
April 21, 2015 10:58
-
-
Save nickedes/4f9f0794e8ec4ab5b546 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class base | |
{ | |
int real,img; | |
public: | |
base () | |
{ | |
real = 0; | |
img = 0; | |
} | |
base (int r,int i):real(r),img(i) {} | |
void input() | |
{ | |
cout<<"enter real and img parts:"; | |
cin >> real >> img; | |
} | |
int getr() {return real;} | |
int geti() {return img;} | |
void display() | |
{ | |
cout<<"Complex no. is:"<<real<<" + i"<<img<<endl; | |
} | |
}; | |
class derived : public base | |
{ | |
public: | |
derived():base() {} | |
derived(int x,int y):base(x,y) | |
{ | |
// real = x; | |
// img = y; | |
} | |
derived sum(derived d,base b) | |
{ | |
// | |
cout << d.getr()<<b.getr()<<d.geti()<<b.geti()<<endl; | |
return derived(d.getr()+b.getr(),d.geti()+b.geti()) ; | |
} | |
}; | |
int main() | |
{ | |
base b(2,5); | |
derived d(4,5),d1; | |
d1 = d1.sum(d,b); | |
d1.display(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment