File tree 1 file changed +49
-0
lines changed
1 file changed +49
-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
+ void setName (string s){
11
+ name=s;
12
+ }
13
+ void getName (){
14
+ cout<<name<<endl;
15
+ }
16
+ student (){
17
+ cout<<" Default Constructor" <<endl;
18
+ }
19
+ student (string s,int a,bool k){
20
+ cout<<" Parameterised Constructor" <<endl;
21
+ name=s;
22
+ age=a;
23
+ gender=k;
24
+ }
25
+ student (student &s){
26
+ cout<<" Copy Constructor" <<endl;
27
+ name=s.name ;
28
+ age=s.age ;
29
+ gender=s.gender ;
30
+ }
31
+ void printInfo (){
32
+ cout<<" Name=" ;
33
+ cout<<name<<endl;
34
+ cout<<" Age=" ;
35
+ cout<<age<<endl;
36
+ cout<<" Gender=" ;
37
+ cout<<gender<<endl;
38
+ }
39
+
40
+ };
41
+ int main () {
42
+
43
+ student a (" Tim" ,18 ,1 );
44
+ student b;
45
+ // or student c(a);
46
+ student c=a;// by default shallow copy else here deep copy as copy constructor present
47
+
48
+ return 0 ;
49
+ }
You can’t perform that action at this time.
0 commit comments