-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructerInInheritance.cpp
More file actions
116 lines (110 loc) · 2.81 KB
/
Copy pathConstructerInInheritance.cpp
File metadata and controls
116 lines (110 loc) · 2.81 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<iostream>
using namespace std;
class Add
{
protected:
int num1, num2;
public:
Add()
{
cout<<"-----------------Parant class Default Constructor-----------"<<endl;
cout<<"Enter the Value of num1 => ";
cin>>num1;
cout<<"Enter the Value of num2 => ";
cin>>num2;
cout<<"Sum = "<< num1 + num2<<endl;
}
Add(int n1, int n2)
{
cout<<"-----------------Parant class Parametrized Constructor-----------"<<endl;
cout<<"Sum = "<< n1 + n2<<endl;
}
~Add()
{
cout<<"----------Parent class Destructors------------"<<endl;
}
};
class Child:public Add
{
private:
int num3, num4;
public:
Child():Add(4,5)
{
cout<<"-----------------Child class Default Constructor-----------"<<endl;
cout<<"Enter the Value of num3 => ";
cin>>num3;
cout<<"Enter the Value of num4 => ";
cin>>num4;
cout<<"Sum = "<< num3 + num4<<endl;
}
~Child()
{
cout<<"-----------Child class Destructor------------"<<endl;
}
};
class Child1:public Add
{
private:
int num3, num4;
public:
Child1():Add()
{
cout<<"-----------------Child1 class Default Constructor-----------"<<endl;
cout<<"Enter the Value of num3 => ";
cin>>num3;
cout<<"Enter the Value of num4 => ";
cin>>num4;
cout<<"Sum = "<< num3 + num4<<endl;
}
~Child1()
{
cout<<"-----------Child1 class Destructor------------"<<endl;
}
};
class Child2:public Add
{
private:
int num3, num4;
public:
Child2()
{
cout<<"-----------------Child2 class Default Constructor-----------"<<endl;
cout<<"Enter the Value of num3 => ";
cin>>num3;
cout<<"Enter the Value of num4 => ";
cin>>num4;
cout<<"Sum = "<< num3 + num4<<endl;
}
~Child2()
{
cout<<"-----------Child2 class Destructor------------"<<endl;
}
};
class Child3:public Add
{
private:
int num3, num4;
public:
Child3(int a, int b):Add(4,5)
{
cout<<"-----------------Child3 class Parametrized Constructor-----------"<<endl;
cout<<"Enter the Value of num3 => ";
cin>>num3;
cout<<"Enter the Value of num4 => ";
cin>>num4;
cout<<"Sum = "<< num3 + num4<<endl;
}
~Child3()
{
cout<<"-----------Child3 class Destructor------------"<<endl;
}
};
int main()
{
Child c;
Child1 c1;
Child2 c2;
Child3 c3(5,6);
return 0;
}