We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is my code.
I do not know why my post is so messy.
Anyway, I think that Person's attribute should be private.
class Person{
private:
string name;
int age;
public:
virtual void getdata(){
cin >> name >> age;
}
virtual void putdata(){
cout << name << " " << age << " ";
}
};
class Professor : public Person{
private:
int publications;
int cur_id;
static int temp;
public:
void getdata(){
Person::getdata();
cin >> publications;
temp++;
cur_id = temp;
}
void putdata(){
Person::putdata();
cout << publications << " " << cur_id << endl;
}
};
class Student : public Person{
private:
int marks;
int cur_id;
static int temp;
public:
void getdata(){
Person::getdata();
for(int i=0;i<6;i++){
int num;
cin >> num;
marks += num;
}
temp++;
cur_id = temp;
}
Virtual Functions
You are viewing a single comment's thread. Return to all comments →
This is my code. I do not know why my post is so messy. Anyway, I think that Person's attribute should be private.
class Person{ private: string name; int age; public: virtual void getdata(){ cin >> name >> age; } virtual void putdata(){ cout << name << " " << age << " "; } };
class Professor : public Person{ private: int publications; int cur_id; static int temp; public: void getdata(){ Person::getdata(); cin >> publications; temp++; cur_id = temp; } void putdata(){ Person::putdata(); cout << publications << " " << cur_id << endl; } };
class Student : public Person{ private: int marks; int cur_id; static int temp; public: void getdata(){ Person::getdata(); for(int i=0;i<6;i++){ int num; cin >> num; marks += num; } temp++; cur_id = temp;
}
void putdata(){ Person::putdata(); cout << marks << " " << cur_id << endl; } };
int Professor::temp = 0; int Student::temp = 0;