Answer to Question #218067 in C++ for Hemambar

Question #218067

Create a person class with name as data member provide four functions in getname() to get input from user and put name 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 Boolean value . Derive student and professor from person. student class should contain gpa as its float type and overrides the virtual functions appropriately . In professor class provide number of applications as data members and override the virtual functions appropriately . Write a main program to declare a array of pointers to person object and depending on the choice from user create either a student object or professor object and store it in person array for n persons and display the details along with whether the person is outstanding or not


1
Expert's answer
2021-07-19T16:58:39-0400
#include <iostream>
using namespace std;


class person{
    private:
        string name;
    public:
        void getname() {
            cout<<"\nEnter name: ";
            cin>>name;
        }
        void  putname(){
            cout<<"\nName is : "<<name<<endl;
        }
        virtual void getdata(){
            
        }
        
        virtual bool outstanding(){
            
        }
};
class student: public person{
    private:
       float gpa; 
    public:
        void getdata(){
            cout<<"\nEnter gpa:";
            cin>>gpa;
        }
        
        bool outstanding(){
            return true;
        }
};
class professor: public person{
    private:
        int app_no;
    public:
        void getdata(){
            cout<<"\nEnter number of applications: ";
            cin>>app_no;
        }
        
        bool outstanding(){
            return true;
        }
};
int main()
{
    int ch;
    cout<<"1. Student\n2. Professor\n";
    cout<<"\nEnter your choice: ";
    cin>>ch;
    
    if (ch==1){
        student s[5];
        for (int i=0;i<5;i++){
            s[i].getname();
            s[i].putname();
            s[i].getdata();
            s[i].outstanding();
        }
    }
    else if(ch==2){
        professor p[5];
        for (int i=0;i<5;i++){
            p[i].getname();
            p[i].putname();
            p[i].getdata();
            p[i].outstanding();
        }
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS