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.
I don't know virtual functions so i tried writing without it and i keep getting this problem which says that Person does not have getdata() and putdata(). Ofcourse it does not have those functions because the professor and student does.
Can someone please tell me where i am going wrong .
include
class Person{
public:
string name;
int age;
};
class Professor: public Person{
public:
int publications , cur_id;
void getdata(){
cin>>cur_id;
cin>>name;
cin>>age;
cin>>publications;
}
void putdata(){
cout<< name << " " << age << " " << publications << " " << cur_id << endl;
}
};
class Student: public Person{
public:
int marks[6] , cur_id , tot_marks = 0;
void getdata(){
cin>>cur_id;
cin>>name;
cin>>age;
for(int i = 0; i < 6; i++){
cin>>marks[i];
}
}
void calculate(){
for(int i = 0; i < 6; i++){
tot_marks = tot_marks + marks[i];
}
}
void putdata(){
cout<< name << " " << age << " " << tot_marks << " " << cur_id << endl;
}
};
Cookie support is required to access HackerRank
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 →
I don't know virtual functions so i tried writing without it and i keep getting this problem which says that Person does not have getdata() and putdata(). Ofcourse it does not have those functions because the professor and student does. Can someone please tell me where i am going wrong .
include
class Person{ public: string name; int age; };
class Professor: public Person{ public: int publications , cur_id; void getdata(){ cin>>cur_id; cin>>name; cin>>age; cin>>publications; } void putdata(){ cout<< name << " " << age << " " << publications << " " << cur_id << endl; } };
class Student: public Person{ public: int marks[6] , cur_id , tot_marks = 0;
};