You are viewing a single comment's thread. Return to all comments →
class Person { public: string name; int age; virtual void getdata() {}; virtual void putdata() {}; }; class Professor: public Person{ public: int publications; static int id; int cur_id; Professor() {cur_id = ++id; } void getdata () { cin>>name; cin>>age; cin>>publications; } void putdata() { cout<<name<<" "<<age<<" "<<publications<<" "<<cur_id <<endl; } }; int Professor:: id = 0; class Student: public Person{ #define NUM_OF_MARKS 6 public: int marks[NUM_OF_MARKS]; static int id; int cur_id; Student() { cur_id = ++id; } void getdata () { cin>>name; cin>>age; for(int i = 0; i < NUM_OF_MARKS; i++) { cin>>marks[i]; } } void putdata() { int sum = 0; for(int i = 0; i < NUM_OF_MARKS; i++) { sum += marks[i]; } cout<<name<<" "<<age<<" "<<sum<<" "<<cur_id <<endl; } }; int Student::id = 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 →