Skip to content

Instantly share code, notes, and snippets.

@nickedes
Created April 21, 2015 10:58
Show Gist options
  • Save nickedes/4f9f0794e8ec4ab5b546 to your computer and use it in GitHub Desktop.
Save nickedes/4f9f0794e8ec4ab5b546 to your computer and use it in GitHub Desktop.
#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