-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vurtual Functions.cpp
83 lines (72 loc) · 1.79 KB
/
Vurtual 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<bits/stdc++.h>
using namespace std;
class Person{
protected:
string name;
int age;
public:
Person(string name, int age){
this->name = name;
this->age = age;
}
virtual void getdata(){}
virtual void putdata(){}
};
class Professor : public Person{
private:
int publications;
int cur_id;
public:
Professor(string name, int age, int publications) : Person(name, age){
this->publications = publications;
cur_id = ++id;
}
void putdata(){
cout << name << " " << age << " " << publications << " " << cur_id << endl;
}
static int id;
};
class Student : public Person{
private:
int marks[6];
int cur_id;
public:
Student(string name, int age, int marks[]) : Person(name, age){
for (int i = 0; i < 6; i++) this->marks[i] = marks[i];
cur_id = ++id;
}
void putdata(){
int sum = 0;
for (int i = 0; i < 6; i++) sum += marks[i];
cout << name << " " << age << " " << sum << " " << cur_id << endl;
}
static int id;
};
int Professor::id = 0;
int Student::id = 0;
int main(){
int n;
cin >> n;
Person *ptr[n];
for (int i = 0; i < n; i++){
int type;
cin >> type;
if (type == 1){
string name;
int age, publications;
cin >> name >> age >> publications;
ptr[i] = new Professor(name, age, publications);
}
else{
string name;
int age, marks[6];
cin >> name >> age;
for (int j = 0; j < 6; j++){
cin >> marks[j];
}
ptr[i] = new Student(name, age, marks);
}
}
for (int i = 0; i < n; i++) ptr[i]->putdata();
return 0;
}