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.
#include <iostream>
using namespace std;
const int LEN = 50; //limit for name string acceptable
////////////////////////////////////////////////////////////////
class employee //employee class
{
private:
char name[LEN]; //employee name
unsigned long number; //employee number
public:
void getdata()
{
cout << "\n Enter last name: "; cin >> name;
cout << " Enter number: "; cin >> number;
}
void putdata() const
{
cout << "\n Name: " << name;
cout << "\n Number: " << number;
}
};
class manager : public employee //management class
{
private:
char title[LEN]; //"vice-president" etc.
double dues; //golf club dues
public:
void getdata()
{
employee::getdata();
cout << " Enter title: "; cin >> title;
cout << " Enter golf club dues: "; cin >> dues;
}
void putdata() const
{
employee::putdata();
cout << "\n Title: " << title;
cout << "\n Golf club dues: " << dues;
}
};
class scientist : public employee //scientist class
{
private:
int pubs; //number of publications
public:
void getdata()
{
employee::getdata();
cout << " Enter number of pubs: "; cin >> pubs;
}
void putdata() const
{
employee::putdata();
cout << "\n Number of publications: " << pubs;
}
};
class laborer : public employee //laborer class
{
};
int main()
{
manager m1[3];
scientist s1[3];
laborer l1[3];
int i,j,k;
for (i=0; i<3; i++)
{
cout << endl; //get data for the employees
cout << "\nEnter data for manager "<<i+1;
m1[i].getdata();
}
for (j=0; j<3; j++)
{
cout << "\nEnter data for scientist "<< j+1;
s1[j].getdata();
}
for (k=0;k<3; k++)
{
cout << "\nEnter data for laborer "<< k+1;
l1[k].getdata();
}
//display data for the employees
for (i=0; i<3; i++)
{
cout << "\nData on manager "<< i+1;
m1[i].putdata();
}
for (j=0; j<3; j++)
{
cout << "\nData on scientist "<< j+1;
s1[j].putdata();
}
for (k=0; k<3; k++)
{
cout << "\nData on laborer "<< k+1;
l1[k].putdata();
}
cout << endl;
return 0;
}
Comments
Leave a comment