You are viewing a single comment's thread. Return to all comments →
class Person { protected: string name; int age, id; public: Person(string n = "", int a = 0, int i = 0) : name(n), age(a), id(i) {} virtual ~Person() {} virtual void getdata() { cin >> name >> age; } virtual void putdata() { cout << name << " " << age << " "; } }; class Professor : public Person { private: int publications; static int id_counter; public: Professor(string n = "", int a = 0, int i = 0, int p = 0) : Person(n, a, i), publications(p) {id = ++id_counter;} void getdata() { Person::getdata(); cin >> publications; } void putdata() { Person::putdata(); cout << publications << " " << id << endl; } }; int Professor::id_counter = 0; class Student : public Person { private: int mark1, mark2, mark3, mark4, mark5, mark6; int static id_counter; public: Student(string n = "", int a = 0, int i = 0, int m1 = 0, int m2 = 0, int m3 = 0, int m4 = 0, int m5 = 0, int m6 = 0) : Person(n, a, i), mark1(m1), mark2(m2), mark3(m3), mark4(m4), mark5(m5), mark6(m6){id = ++id_counter;} void getdata() { Person::getdata(); cin >> mark1 >> mark2 >> mark3 >> mark4 >> mark5 >> mark6; } void putdata() { Person::putdata(); cout << mark1 + mark2 + mark3 + mark4 + mark5 + mark6 << " " << id << endl; } }; int Student::id_counter = 0;
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 →