-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_constructor.cpp
51 lines (43 loc) · 1016 Bytes
/
default_constructor.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
#include<iostream>
#include<string>
using namespace std;
//GradeBook class definition
class GradeBook{
private:
string courseName;
int year;
public:
GradeBook(){
courseName = "CSE";
year = 1;
}
string getCourseName(){
return courseName;
}
void setCourseName(string courseName){
this->courseName = courseName;
}
int getYear(){
return year;
}
void setYear(int year){
this->year = year;
}
};
//main function starts here
int main(){
GradeBook gb1;
cout<<"Object 1 Before Changes"<<endl;
cout<<gb1.getCourseName()<<" => "<< gb1.getYear()<<endl;
gb1.setCourseName("EC");
gb1.setYear(3);
cout<<"Object 1 After Changes"<<endl;
cout<<gb1.getCourseName()<<" => "<< gb1.getYear()<<endl;
GradeBook gb2;
cout<<"Object 2 Before Changes"<<endl;
cout<<gb2.getCourseName()<<" => "<< gb2.getYear()<<endl;
gb2.setCourseName("Mechanical");
gb2.setYear(4);
cout<<"Object 2 After Changes"<<endl;
cout<<gb2.getCourseName()<<" => "<< gb2.getYear()<<endl;
}