File tree 1 file changed +53
-0
lines changed
1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Online C++ compiler to run C++ program online
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+ class student {
5
+ string name;
6
+ public:
7
+ int age;
8
+ bool gender;
9
+
10
+ ~student (){
11
+ cout<<" Destructor called" <<endl;// at end of main fucntion
12
+ }
13
+
14
+ void setName (string s){
15
+ name=s;
16
+ }
17
+ void getName (){
18
+ cout<<name<<endl;
19
+ }
20
+ student (){
21
+ cout<<" Default Constructor" <<endl;
22
+ }
23
+ student (string s,int a,bool k){
24
+ cout<<" Parameterised Constructor" <<endl;
25
+ name=s;
26
+ age=a;
27
+ gender=k;
28
+ }
29
+ student (student &s){
30
+ cout<<" Copy Constructor" <<endl;
31
+ name=s.name ;
32
+ age=s.age ;
33
+ gender=s.gender ;
34
+ }
35
+ void printInfo (){
36
+ cout<<" Name=" ;
37
+ cout<<name<<endl;
38
+ cout<<" Age=" ;
39
+ cout<<age<<endl;
40
+ cout<<" Gender=" ;
41
+ cout<<gender<<endl;
42
+ }
43
+
44
+ };
45
+ int main () {
46
+
47
+ student a (" Tim" ,18 ,1 );
48
+ student b;
49
+ // or student c(a);
50
+ student c=a;// by default shallow copy else here deep copy as copy constructor present
51
+
52
+ return 0 ;
53
+ }
You can’t perform that action at this time.
0 commit comments