-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtual.cpp
113 lines (92 loc) · 1.53 KB
/
virtual.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
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
#include <iostream>
using namespace std;
class Person
{
private:
string name{};
int age{};
public:
virtual void getdata()
{
cin >> name >> age;
}
virtual void putdata()
{
cout << name << " " << age << " ";
}
};
class Professor : public Person
{
private:
static int idp;
int cur_id{};
int publications{};
public:
Professor()
{
cur_id = ++idp;
}
void getdata() override
{
Person::getdata();
cin >> publications;
}
void putdata() override
{
Person::putdata();
cout << publications << " " << cur_id << endl;
}
};
class Student : public Person
{
private:
int marks[6]{};
static int ids;
int cur_id;
int sum = 0;
public:
Student()
{
cur_id = ++ids;
}
void getdata() override
{
Person::getdata();
for (int i = 0; i < 6; i++)
{
cin >> marks[i];
sum += marks[i];
}
}
void putdata() override
{
Person::putdata();
cout << sum << " " << cur_id << endl;
}
};
int Professor::idp = 0;
int Student::ids = 0;
int main()
{
int n, val;
cin >> n;
Person *per[n];
for (int i = 0; i < n; i++)
{
cin >> val;
if (val == 1)
{
per[i] = new Professor;
}
else
{
per[i] = new Student;
}
per[i]->getdata();
}
for (int i = 0; i < n; i++)
{
per[i]->putdata();
}
return 0;
}