-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinherit_q1.cpp
78 lines (73 loc) · 1.18 KB
/
inherit_q1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#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) {}
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()) ;
}
friend class derv;
};
class derv
{
int d_real,d_img;
public:
derv ()
{
d_real = 0;
d_img = 0;
}
derv (int r,int i):d_real(r),d_img(i) {}
void input()
{
cout<<"enter real and img parts:";
cin >> d_real >> d_img;
}
int getr() {return d_real;}
int geti() {return d_img;}
void display()
{
cout<<"Complex no. is:"<<d_real<<" + i"<<d_img<<endl;
}
void diff(base &d)
{
cout<<"Complex no. is:"<<d_real - d.getr()<<" + i"<<d_img - d.geti()<<endl;
}
};
int main()
{
base b(2,5);
derived d(4,5),d1;
d1 = d1.sum(d,b);
d1.display();
derv x(5,9);
x.diff(b);
return 0;
}