Answer to Question #201689 in C++ for Sohan Pulluru

Question #201689

This program models a database of employees of a company. There are three kinds of 

employees in the company: manager, scientist and laborers. The database stores a 

name and an employee identification number of all employees, no matter what their 

category. However, for manager, it also stores their title and golf club dues. For 

scientists, it stores the number of articles they have published. Laborers need no 

additional data beyond their names and numbers. All information to be obtained through 

a member function getdata(). Information about each employee are to displayed 

through a constant member function putdata(). Define appropriate classes, member 

functions. Create an array of objects of each employee type (manager, scientist and 

laborers separately). Your program should able to read information about each 

employee type and display the same. 


1
Expert's answer
2021-06-01T15:00:34-0400
#include <iostream>
using namespace std;
class Employee{
    protected:
        char name[20];
        int id;
    public: 
        Employee(){}
        virtual void getdata(){
            cout<<"Enter employee name: "; cin>>name;
            cout<<"Enter employee id: "; cin>>id;
        }
        virtual void putdata() const{
            cout<<"Employee name: "<<name<<endl;
            cout<<"Employee id: "<<id<<endl;
        }
};
class Manager:public Employee{
    char title[30], golf_club_dues[20];
    public:
        Manager(): Employee() {}
        void getdata(){
            Employee::getdata();
            cout<<"Enter manager title: "; cin>>title;
            cout<<"Enter golf club dues: "; cin>>golf_club_dues;
        }
        void putdata() const{
            Employee::putdata();
            cout<<"Employee type: Manager"<<endl;
            cout<<"Manager title: "<<title<<endl;
            cout<<"Golf club dues: "<<golf_club_dues<<endl<<endl;
        }
};
class Scientist: public Employee{
    int publications;
    public: 
        Scientist(): Employee(){}
        void getdata(){
            Employee::getdata();
            cout<<"Enter number of publications: "; cin>>publications;
        }
        void putdata() const{
            Employee::putdata();
            cout<<"Employee type: Scientist"<<endl;
            cout<<"Number of publications: "<<publications<<endl<<endl;
        }
};
class Laborer: public Employee{
    public:
        Laborer(): Employee(){}
        void getdata(){
            Employee::getdata();
        }
        void putdata() const{
            Employee::putdata();
            cout<<"Employee type: Laborer"<<endl<<endl;
        }
};
int main(){
    int mgrs = 0, scs = 0, lbrs = 0;
    Manager (*managers)[1] = new Manager[20][1];
    Scientist (*scientists)[1] = new Scientist[50][1];
    Laborer (*laborers)[1] = new Laborer[100][1];


    int choice, choice2;


    do{
        cout<<"1. Add an Employee to database.\n";
        cout<<"2. View Employees in database.\n";
        cin>>choice;
        switch(choice){
            case 1: cout<<"1. Add a manager\n";
                    cout<<"2. Add a scientist\n";
                    cout<<"3. Add a laborer\n";
                    cin>>choice2;
                    switch(choice2){
                        case 1: mgrs++;
                                managers[mgrs - 1]->getdata();
                                break;
                        case 2: scs++;
                                scientists[scs - 1]->getdata();
                                break;
                        case 3: lbrs++;
                                laborers[lbrs - 1]->getdata();
                                break;
                        default: break;
                    }
                    break;
            case 2: cout<<"1. View managers\n";
                    cout<<"2. View scientists\n";
                    cout<<"3. View laborers\n";
                    cin>>choice2;
                    switch(choice2){
                        case 1: for(int i = 0; i < mgrs; i++) managers[i]->putdata();
                                if(mgrs == 0) cout<<"There are currently no managers in the database\n";
                                break;
                        case 2: for(int i = 0; i < scs; i++) scientists[i]->putdata();
                                if(scs == 0) cout<<"There are currently no scientists in the database\n";
                                break;
                        case 3: for(int i = 0; i < lbrs; i++) laborers[i]->putdata();
                                if(lbrs == 0) cout<<"There are currently no laborers in the database\n";
                                break;
                        default: break;
                    }
                    break;
            default: break;
            }
        }while(choice > 0 && choice < 3);
    
    
    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