-
Notifications
You must be signed in to change notification settings - Fork 0
/
21.1.2.cpp
70 lines (61 loc) · 1.27 KB
/
21.1.2.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
#include<iostream>
#include<string>
using namespace std;
// Constructor
class student{
string name;
int age;
bool gender;
public:
// Deafault Constructor
student(){
cout<<"Default Constructor"<<endl;
}
// Parameterized constructor
student(string n, int a, bool g){
cout<<"Parameterised Constructor"<<endl;
name = n;
age = a;
gender = g;
}
// Copy Constructor
student(student &a){
cout<<"Copy Constructor"<<endl;
name = a.name;
age = a.age;
gender = a.gender;
}
// Destructor
~student(){
cout<<"Destructor for object "<<name<<endl;
}
void getName(){
cout<<name<<endl;
}
void printInfo(){
cout<<name<<" ";
cout<<age<<" ";
cout<<gender<<" ";
cout<<endl;
}
bool operator == (student &a){
if(name == a.name && age == a.age && gender == a.gender)
return true;
else
return false;
}
};
int main(){
student a("Aman", 20, 0);
// a.getName();
a.printInfo();
student b;
student c = a;
c.printInfo();
student d("Aman", 20, 0);
bool res = a==d;
cout<<res<<endl;
res = a==b;
cout<<res<<endl;
return 0;
}