You are viewing a single comment's thread. Return to all comments →
class Person { public: virtual void getdata() = 0; virtual void putdata() = 0;
protected: string name{}; int age{};
};
class Professor : public Person {
private: int publications{}; static int prof_seq_id; int prof_cur_id{};
public: Professor() :prof_cur_id {prof_seq_id} { prof_seq_id++; }
void getdata() override { cin >> name; cin >> age; cin >> publications; }
void putdata() override { cout << name << " " << age << " " << publications << " " << prof_cur_id << endl; }
int Professor::prof_seq_id = 1;
class Student : public Person {
private: vector marks; int stud_cur_id {}; int sum; static int stud_seq_id;
public: Student() :stud_cur_id{stud_seq_id} { stud_seq_id++; } void getdata() override { cin >> name; cin >> age; int num; for(int i = 0; i < 6; i++) { cin >> num; marks.emplace_back(num); } } void putdata() override { sum = accumulate(marks.begin(), marks.end(), 0); cout << name << " " << age << " " << sum << " " << stud_cur_id << endl; }
int Student::stud_seq_id = 1;
Seems like cookies are disabled on this browser, please enable them to open this website
Virtual Functions
You are viewing a single comment's thread. Return to all comments →
class Person { public: virtual void getdata() = 0; virtual void putdata() = 0;
};
class Professor : public Person {
private: int publications{}; static int prof_seq_id; int prof_cur_id{};
public: Professor() :prof_cur_id {prof_seq_id} { prof_seq_id++; }
void getdata() override { cin >> name; cin >> age; cin >> publications; }
void putdata() override { cout << name << " " << age << " " << publications << " " << prof_cur_id << endl; }
};
int Professor::prof_seq_id = 1;
class Student : public Person {
private: vector marks; int stud_cur_id {}; int sum; static int stud_seq_id;
};
int Student::stud_seq_id = 1;