-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP93oops.cpp
More file actions
90 lines (66 loc) · 1.54 KB
/
P93oops.cpp
File metadata and controls
90 lines (66 loc) · 1.54 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
// CONSTRUCTORS
#include<iostream>
using namespace std;
class student{
//string name; it is in private to access this we can use set func
public:
string name;
int age;
bool gender;
// default constructor
student(){
cout<<"default constructor"<<endl;
}
// parameterised constructor
student(string s, int a, int g){
cout<<"parameterised constructor"<<endl;
name=s;
age=a;
gender=g;
}
// copy constructor
student(student &a){
cout<<"copy constructor"<<endl;
name=a.name;
age=a.age;
gender=a.gender;
}
// destructors(parameters cannot be passed and cant be return)
~student(){
cout<<"destructor called"<<endl;
}
// void setName(string s){ // setter function
// name=s;
// }
// void getName(){ // get function
// cout<<name<<endl;
// }
void printInfo(){
cout<<"name: ";
cout<<name<<endl;
cout<<"age: ";
cout<<age<<endl;
cout<<"gender: ";
cout<<gender<<endl;
}
// operator overloading
bool operator == (student &a){
if (name==a.name && age==a.age && gender==a.gender)
{
return true;
}
return false;
}
};
int main(){
student a("preethi",20,1);
// a.printInfo();
student b;
student c=a;
if (c==a)
{
cout<<"same"<<endl;
} else
cout<<"not same";
return 0;
}