-
Notifications
You must be signed in to change notification settings - Fork 222
/
virtual-functions.cpp
59 lines (57 loc) · 1.26 KB
/
virtual-functions.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
52
53
54
55
56
57
58
59
class Person {
public:
string name;
int age;
virtual void getdata() {
cin >> this->name >> this->age;
}
virtual void putdata() {
cout << this->name << " " << this->age << endl;
}
};
class Professor : public Person {
public:
Professor() {
this->cur_id = ++id;
}
int publications;
static int id;
int cur_id;
void getdata() {
cin >> this->name >> this->age >> this->publications;
}
void putdata() {
cout << this->name << " "
<< this->age << " "
<< this->publications << " "
<< this->cur_id << endl;
}
};
int Professor::id = 0;
class Student : public Person {
#define NUM_OF_MARKS 6
public:
Student() {
this->cur_id = ++id;
}
int marks[NUM_OF_MARKS];
static int id;
int cur_id;
void getdata() {
cin >> this->name >> this->age;
for (int i=0; i<NUM_OF_MARKS; i++) {
cin >> marks[i];
}
}
void putdata() {
int marksSum = 0;
for (int i=0; i<NUM_OF_MARKS; i++) {
marksSum += marks[i];
}
cout << this->name << " "
<< this->age << " "
<< marksSum << " "
<< this->cur_id << endl;
}
};
int Student::id = 0;