You are viewing a single comment's thread. Return to all comments →
what's wrong in my code, in the output, in place of cur_id, for all classes, i.e for both Professor and Student, i getting only as value 3.
that is: I getting the output as...
Walter 56 99 2 Jesse 18 403 2 Pinkman 22 135 2 White 58 87 2
Instead of
Walter 56 99 1 Jesse 18 403 1 Pinkman 22 135 2 White 58 87 2
Here's my code, can someone explains me why
class Person { public: string name; int age; virtual void getdata() { } virtual void putdata() { } }; class Professor : public Person { public: int publications; static int cur_id; Professor() { cur_id++; } void getdata() { cin>>name>>age>>publications; } void putdata() { cout<<name<<" "<<age<<" "<<publications<<" "<<cur_id<<endl; } }; int Professor::cur_id = 0; class Student : public Person { public: int marks[6],sum=0; static int cur_id; Student() { cur_id++; } void getdata() { cin>>name>>age; for(int i=0;i<6;i++) cin>>marks[i]; } void putdata() { cout<<name<<" "<<age<<" "; for(int i=0;i<6;i++) sum+=marks[i]; cout<<sum<<" "<<cur_id<<endl; } }; int Student::cur_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 →
what's wrong in my code, in the output, in place of cur_id, for all classes, i.e for both Professor and Student, i getting only as value 3.
that is: I getting the output as...
Instead of
Here's my code, can someone explains me why