create a person class with name as it's data member . provide 4 functions getname() to get input from user and putname() to display output. Write two virtual functions getdata() and outstanding() where both these functions takes no argument and getdata() returns no value but outstanding () returns a Boolean value. Derive student and professor from person. student class should contain GPA as its float type data member and overrides the virtual functions appropriately .in professor class provide number of publications as data member and overrides the virtual functions appropriately. write a main program to declare an array of pointers to person object and depending on the choice from user create a student object or professor object and store it in person array for n persons. display the details along with whether the person is outstanding or not
#include<iostream>
#include<vector>
using namespace std;
class Person{
private:
string name;
public:
string getname(){
cout<<"Enter the user name\n";
cin>>name;
return name;
}
void putname(){
cout<<"The user name is \t"<<getname()<<endl;
}
virtual void getdata(){
}
virtual bool outstanding(){
}
};
class student: public Person{
private:
float GPA;
public:
void getData(){
cout<<"Enter the GPA\n";
cin>> GPA;
}
bool outstanding(){
return true;
}
};
class Professor: public Person{
private:
int numberOfPublication;
public:
void getData(){
cout<<"Enter the number of publications\n";
cin>> numberOfPublication;
cout<<"Enter the number of publications\t"<<numberOfPublication<<endl;
}
bool outstanding(){
return true;
}
};
int main(){
Person p;
vector<Person>{p};
Professor pr;
student s;
s.putname();
pr.getdata();
}
Comments
Leave a comment