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