-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopyconstructor.cpp
More file actions
59 lines (50 loc) · 1.2 KB
/
copyconstructor.cpp
File metadata and controls
59 lines (50 loc) · 1.2 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
#include<iostream>
#include<string>
using namespace std;
class Teacher{
private:
double salary; //data hiding
public:
string name;
string dept;
string subject;
void changeDept(string newDept){
dept=newDept;
}
//getter setter
void setSalary(double s){
salary=s;
}
int getSalary(){
return salary;
}
Teacher(){
cout<<"constructor is calling"<<endl;
}
Teacher(string s,string d, string sub, double sal){
this->name=s; // to access the object properties, then use this keyword.
this->dept=d;
this->subject=sub;
this->salary=sal;
}
void getInfo(){
cout<<"Teacher name "<<name<<endl;
cout<<"Teacher subject "<<subject<<endl;
}
};
int main(){
// Teacher t1;
// t1.name="sarang";
// t1.subject="Math";
// t1.changeDept("CSE");
// t1.getInfo();
// t1.setSalary(100);
// int salary= t1.getSalary();
// cout<<salary<<endl;
Teacher t1("sumedh","CSE","C++",1500000);
t1.getInfo();
Teacher t2(t1);
t2.getInfo();
// cout<<t1.name<<endl;
return 0;
}