-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc++Bigbang
142 lines (110 loc) · 3.26 KB
/
c++Bigbang
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
130
131
132
133
134
135
136
137
138
139
140
141
142
#include<iostream>
using namespace std;
//******************************************************************base class************************************************
class student
{
private:
string studentName;
int stuEnrollyear;
public:
// constructor
student()
{
}
//setting variable to specific value holder variables
student(string studentName,int stuEnrollyear)
{
studentName=studentName;
stuEnrollyear=stuEnrollyear;
}
//creating get name function
string Getname()
{
return studentName;
}
// creating getEnrollmentyear function
int GetEnrollmentyear()
{
return stuEnrollyear;
}
//setting name function
void setName(string name)
{
studentName=name;
}
// setting Entrollyear function
void setEnrollyear(int entrollmentYear)
{
stuEnrollyear=entrollmentYear;
}
// distructor
~student()
{
}
virtual void print()
{
cout <<"StudentNAME : "<<studentName<<endl<<"EnrollmentYEAR : "<<stuEnrollyear <<endl;
}
};
//******************************************************subclass inherited from the base class***************************************************************************
class KpuStudent:public student
{
private:
string campusLocation;
public: KpuStudent(string studentName,int stuEnrollyear,string campusLocation);
student(string studentName,int stuEnrollyear)
{
campusLocation=campusLocation;
}
// getting campuslocation using getfunction
string getcampslocation()
{
return campusLocation;
}
//setting campuslocation using setfunction
void setcampuslocation(string location)
{
campusLocation=location;
}
virtual void print()
{
cout <<"studentName : "<<Getname()<<endl<<"CampusLocation :"<<campusLocation <<endl;
}
};
//********************************************************second subclass inherited from the base class **************************************************************
class HogwartsStudent:public student
{
private:
string houseAffiliation;
public: HogwartsStudent(string studentName,int stuEnrollyear,string houseAffiliation);
student(string studentName,int stuEnrollyear)
{
houseAffiliation=houseAffiliation;
}
//
string getHouseAffiliation() {
return houseAffiliation;
}
//
void setHouseAffiliation(string houseAffiliation) {
houseAffiliation = houseAffiliation;
}
//
virtual void print()
{
cout <<"StudentNAME : "<<Getname()<<endl<<"houseAffiliation : "<<houseAffiliation <<endl;
}
};
int main()
{
student s1=student("Pritpal Singh",2021);
KpuStudent s2=KpuStudent("Pritpal Singh",2021,"surry");
HogwartsStudent s3=HogwartsStudent("Pritpal Singh",2021,"Ravenclaw");
student *stdnt[3];
stdnt[0]=&s1;
stdnt[1]=&s2;
stdnt[2]=&s3;
for(int i = 0; i < 3; i++) {
stdnt[i]->print();
}
}