Answer to Question #201688 in C++ for Myname

Question #201688

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:36-0400
#include <iostream>


using namespace std;
class Employee{
    protected:
        string name;
        int id;
};
class Manager:public Employee{
    private:
        string title;
        string golf_club_dues;
    public:
     void getData(){
         cout<<"\nEnter name: ";
         cin>>name;
         cout<<"\nEnter id: ";
         cin>>id;
         cout<<"Enter title: ";
         cin>>title;
         cout<<"\nEnter golf club dues: ";
         cin>>golf_club_dues;
     }
       void putData() const{
         cout<<"\nName: "<<name<<endl;
         cout<<"\nid: "<<id<<endl;
         cout<<"\nTitle: "<<title<<endl;
         cout<<"\nGolf club dues: "<<golf_club_dues<<endl;
     }  
};
class Scientist:public Employee{
    private:
        int no_articles;
    public:
     void getData(){
         cout<<"\nEnter name: ";
         cin>>name;
         cout<<"\nEnter id: ";
         cin>>id;
         cout<<"Enter number of articles published: ";
         cin>>no_articles;
         
     }
     void putData() const{
         cout<<"\nName: "<<name<<endl;
         cout<<"\nid: "<<id<<endl;
         cout<<"\nNumber of articles: "<<no_articles<<endl;
     } 
};
class Laborers:public Employee{
    public:
     void getData(){
         cout<<"\nEnter name: ";
         cin>>name;
         cout<<"\nEnter id: ";
         cin>>id;
     }
     void putData() const{
         cout<<"\nName: "<<name<<endl;
         cout<<"\nid: "<<id<<endl;


     } 
};
int main()
{
    Manager m[4];
    Scientist s[4];
    Laborers l[4];
    //managers
    for(int i=0; i < 4; i++) {
        m[i].getData();
    }
    for(int i=0; i < 4; i++) {
        m[i].putData();  
    }
    //Scientists
    for(int i=0; i < 4; i++) {
        s[i].getData();
    }
    for(int i=0; i < 4; i++) {
        s[i].putData();  
    }
    //Laborers
    for(int i=0; i < 4; i++) {
        l[i].getData();
    }
    for(int i=0; i < 4; i++) {
        l[i].putData();  
    }
    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