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
using namespace std;
#include <omp.h>
#include <stdio.h>
// 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
#define NO_OF_PERSONS 3
#define STDNT 1
#define PROF 2
class Person
{
public:
string name;
void getname(string s)
{
name = s;
}
void putname(string s)
{
cout<<"\nName: "<<s;
}
void getdata(void)
{
}
bool outstanding(void)
{
}
};
class Student:public Person
{
public:
float GPA;
void getGPA(float gpa)
{
GPA = gpa;
}
};
class Professor:public Person
{
public:
int No_of_Publications;
void getPublications(int n)
{
No_of_Publications=n;
}
};
main(void)
{
class Student S[NO_OF_PERSONS];
class Professor P[NO_OF_PERSONS];
int Flag=1,n,S_P,CountS=0,CountP=0;
string temp;
float g;
int nop;
while(Flag)
{
S_P=-1;
cout<<"\nPress 1 to Select Student Data.";
cout<<"\nPress 2 to Select Professor Data.";
cout<<"\nPress 3 to display Students list";
cout<<"\nPress 4 to display Professors list";
cout<<"\nPress 0 to Quit";
Flag=-1;
while(Flag<0 || Flag>4)
{
cout<<"\n\nEnter Option (0 to 4): "; cin>>Flag;
}
if(Flag==STDNT)
{
if(CountS<NO_OF_PERSONS)
{
cout<<"\n\nEnter the name of Student: "; cin>>temp;
S[CountS].getname(temp);
cout<<"\nEnter the GPA: "; cin>>g;
S[CountS].getGPA(g);
CountS++;
}
else
cout<<"\nMax. Students ("<<NO_OF_PERSONS<<") limit exhausted. No more students are allowed.";
}
if(Flag==PROF)
{
if(CountP<NO_OF_PERSONS)
{
cout<<"\n\nEnter the name of Professor: "; cin>>temp;
P[CountP].getname(temp);
cout<<"\nEnter the no. of publications: "; cin>>nop;
P[CountP].getPublications(nop);
CountP++;
}
else
cout<<"\nMax. Professors ("<<NO_OF_PERSONS<<") limit exhausted. No more professors are allowed.";
}
if(Flag==3)
{
cout<<"\nStudent's Data";
for(n=0;n<CountS;n++)
{
cout<<"\nStudent Name: "<<S[n].name<<"\tGPA = "<<S[n].GPA;
}
}
if(Flag==4)
{
cout<<"\nProfessor's Data";
for(n=0;n<CountP;n++)
{
cout<<"\nProfessor Name: "<<S[n].name<<"\tNo. of Publications = "<<P[n].No_of_Publications;
}
}
}
}
Comments
Leave a comment