Descritpion
Submission
There are 2 major points here, pure virtual function and static member variable.
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; class Person { protected: string name; int age; int cur_id; public: virtual void getdata() = 0; virtual void putdata() = 0; }; class Professor : public Person { int publications; static int id; public: void getdata() { cin >> name >> age >> publications; cur_id = ++Professor::id; } void putdata() { cout << name << " " << age << " " << publications << " " << cur_id << endl;; } }; class Student : public Person { int sum; static int id; public: void getdata() { cin >> name >> age; sum = 0; for(int i = 0; i < 6; i++) { int tmp; cin >> tmp; sum += tmp; } cur_id = ++Student::id; } void putdata() { cout << name << " " << age << " " << sum << " " << cur_id << endl; } }; int Professor::id = 0; int Student::id = 0; int main(){