-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoops_apancollage.cpp
More file actions
129 lines (108 loc) · 2.54 KB
/
Copy pathoops_apancollage.cpp
File metadata and controls
129 lines (108 loc) · 2.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <string>
using namespace std;
class Teacher{
// properties attributes
private:
double salary;
public:
Teacher() {
cout << "HI , I am constructor\n";
}
string name;
string dept;
string subject;
//parameterized
Teacher(string name, string dept, string subject , double salary){
this->name = name;
this->dept = dept;
this->subject = subject;
this->salary = salary;
}
// copy constructor
Teacher(Teacher &orgObj){
cout << "i am custom copy constuctor...\n";
this->name = orgObj.name;
this->dept = orgObj.dept;
this->subject = orgObj.subject;
this->salary = orgObj.salary;
}
// methods or member function
void changeDept(string newDept){
dept = newDept;
}
void getInfo(){
cout << "name :" << name << endl;
cout << "subject : " << subject << endl;
}
//setter
void setSalary(double s){
salary = s;
}
//getter
double getSalary(){
return salary;
}
};
class Student{
public:
string name;
int rollno;
int age;
};
class Account{
private:
double balance;
string password; // data hiding
public:
string accountID;
string username;
};
class Student2{
public:
string name;
// double cgpa; for hallow copy
double* cgpaPtr;
Student2(string name, double cgpa){
this->name = name;
// this->cgpa = cgpa; for hallow copy
cgpaPtr = new double;
*cgpaPtr = cgpa;
}
Student2(Student2 &obj){
this->name = obj.name;
//this->cgpa = obj.cgpa;
this->cgpaPtr = obj.cgpaPtr;
cgpaPtr = new double;
*cgpaPtr = *obj.cgpaPtr;
}
void getInfo(){
cout << "name : " << name << endl;
//cout << "cgpa : " << cgpa << endl; // for hallow copy
cout << "cgpa : " << *cgpaPtr << endl;
}
};
int main(){
// Teacher t1; // internally calling the constructor
// Teacher t2;
// t1.name = "Aditya";
// t1.dept = "ECE";
// t1.subject = "VLSI";
// t1.setSalary(25000);
Teacher t1("Shradha", "ComputerScience", "c++", 25000);
t1.getInfo();
Teacher t2(t1); // default copy constructor --invoke
t2.getInfo();
cout << t1.name << endl;
cout << t1.getSalary() << endl;
cout << endl;
Student2 s1("rahul kumar", 8.9);
s1.getInfo();
Student2 s2(s1);
s2.getInfo();
*(s2.cgpaPtr) = 9.2;
s1.getInfo();
s2.name = "neha";
s2.getInfo();
return 0;
}