-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirtual Functions
60 lines (51 loc) · 1.11 KB
/
Virtual Functions
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
class Person
{
friend class Professor;
friend class Student;
string Name;
int age;
public:
virtual void getdata() {;};
virtual void putdata() {;};
};
class Professor : public Person
{
static int all_id;
int curr_id;
int publications;
public:
Professor(){curr_id = all_id; ++all_id;};
void getdata() override;
void putdata() override;
};
class Student : public Person
{
static int all_id;
int curr_id;
vector <float> marks = vector<float>(6);
float sum;
public:
Student(){curr_id = all_id; ++all_id;};
void getdata() override;
void putdata() override;
};
int Professor::all_id=1;
int Student::all_id=1;
void Professor::getdata()
{
cin >> Name >> age >> publications;
}
void Professor::putdata()
{
cout << Name<<" " << age<<" " << publications <<" "<<curr_id<<endl;
}
void Student::getdata()
{
cin >> Name >> age >> marks[0] >> marks[1]>> marks[2]>> marks[3]>> marks[4]>> marks[5];
for (auto& n : marks)
sum += n;
}
void Student::putdata()
{
cout << Name<<" " << age<<" "<<sum<<" "<<curr_id<<" "<<endl;
}