Documente Academic
Documente Profesional
Documente Cultură
Exercise 9)
Mini-Project: Human Resource Management Program
Consider that you want to write a program for the company called XYZ which produces
medical instruments. This company is divided into 2 departments: Manufacturing
Department (MD) and Human Resource Management department (HRM). You are
requested to write a program for HRM department of company XYZ including the maximum
number of 100 employees. shows main menu for your program. You are allowed to redesign this menu but with the same functionalities. Note that after each step you should
come back to main menu.
Welcome to Human Resource Management (HRM) Software of Company XYZ. To do
specific task please choose one of the following commands.
1. Add new employee
2. Delete employee information
3. Update employee information
4. Make reports based on specific field
5. Search employee
6. Quit
Please enter the related number of your requested command?
You should use class definition Person (See Figure 3.2) and class definition HRM (See
Figure 3.3). Note that in class Person, setting the values for all fields is not possible. You
have to calculate the value for the field Salary after initializing the fields WorkingHours
and CostPerHour by user. For those which the set function works, the validity of the
entered data should be checked. For example, negative values for fields Salary,
WorkingHours and CostPerHour are not accepted. As another example the field
WorkingHours should be between 1 and 60.
The field PersonalID of class Person should be unique and auto-increment with the initial
value of 8921001 for the first employee. It means that user should not enter the value for
personalID.
Class HRM should include following private fields:
Array of employees with the type Person (Private)
The actual amount of staff which is stored in Array of employees(private)
Class HRM should include following public member functions:
AddPerson()
DeletePerson()
UpdatePerson()
ReportList()
SearchPerson()
Please note that you need to check the actual amount of employees and in case of reaching
to the number 100 for the total number of employees you should give proper message. For
the actual amount of employees you should not enter the value yourself and your program
should calculate automatically the amount while entering or deleting the information of an
employee.
Based on the description of the program, you need to define some arguments for functions
DeletePerson(), UpdatePerson(), ReportList(), SearchPerson() instead of ().
1. AddPerson()
This function allows users to enter the related information of employees in class HRM.
During the initialization step your program should get the working hours per week (e.g. 35)
for the employee and the payment for his/her work per hour. Then, you should calculate the
total salary for him/her per year. You should consider 52 working weeks for one year in your
calculations. shows the sample output of this function.
4. ReportList()
In this function, user can choose a specific field to make reporting. These fields can be
Family Name or Salary. You could use Figure 3.7 as a basic for your development. The
list will be sorted ascending based on the requested field.
Please enter the related number of the field which you would like to sort the list based on it.
(1. Family name, 2.Salary)? 2
Following is the result:
First Name Family Name Personal Number salary (Euro)
-------------- ---------------- ---------------------- ---------------Alex Peterson 8921001 45500.00
5. SearchPerson()
In this function, user can find specific people using chosen fields. These fields can be
Family Name or Salary. You could use Figure 3.8 as a basic for your development.
By using salary as a search field, user should define minimum and maximum values for
search. As a result he/she will get the list of employees who their salary is between
requested Min_Salary and Max_salary. For searching the employee with specific amount of
salary, user should define same Min_Salary and Max_Salary values.
By using the Family Name as a search field user will get the list of employees who their
family name is equal to requested family name.
Search is based on two different fields (1.family name, 2.Salary), please enter your choice?
2
Please define your search range for salary of employees (S_min, S_max).
What is minimum salary for search (S_min)? 60000
What is maximum salary for search (S_max)? 110000
Following is the list of employees for your defined search fields:
First Name Family Name Personal Number salary (Euro)
-------------- ---------------- ---------------------- ---------------Martin Klein 8921003 81900.00
Sarah Mller 8921004 105300.00
Do you want to do new search (y/n)? y
Search is based on two different fields (1.family name, 2.Salary), please enter your choice?
1
Please enter the family name of employee? Peterson
Following is the list of employees for your defined search fields:
First Name Family Name Personal Number salary (Euro)
-------------- ---------------- ---------------------- ---------------Alex Peterson 8921001 45500.00
Do you want to do new search (y/n)? n
Solution#include<iostream>
#include<math.h>
#include<cstdlib>
#include<string>
using namespace std;
class Person
{
private :
string FirstName;
// student name, max 49 characters
string LastName;
// student family name
int PersonalID ;
double Salary ;
double WorkingHours ;
double CostPerHour ;
public :
void set_FieldName();
void get_FieldName();
void gett_FieldName();
void set_PersonalID();
void set_Name();
void LastNamesortList();
void in_FirstName();
void in_FamilyName();
void in_Workinghour();
void in_Costperhour();
};
class HRM
{
private :
Person e[100] ;
Person temp[100];
public :
void
void
void
void
void
};
AddPerson();
DeletePerson();
SearchPerson();
UpdatePerson();
ReportList();
/////////////////////////////////////////////////////////////////////
//
Definition of the AddPerson() method of the Company class
//
This method will add an employee to the Company class instance.
//
The attributes of the employee should be those of the user's
//
own choosing.
void ::HRM::AddPerson() {
int x;
char redo;
do
{
n++;
e[i].set_FieldName();
i++;
cout<<"\nThe employee with the following information has
been added to the system:"<<endl;
cout<<"\nFirst Name
Last Name
Personal ID
Salary per year (Euros)";
cout<<"\n--------------------------- ------------------------------------"<<endl;
//cout<<"naaaaaaaaaaaam"<< n<<endl;
for(int i=0; i<n; i++){
e[i].get_FieldName();
}
//
//
//
/////////////////////////////////////////////////////////////////////
Definition of the DeletePerson() method of the Company class.
This method will delete the employee of the user's choosing from
the Company class instance.
void HRM::DeletePerson() {
//
Show all of the current employees
//
Ask the user the ID of which employee that they wish to
//
delete.
int empId;
bool lol;
char redo1,redo2;
lol =false;
lebel:
cout << "ID of employee to remove: ";
if (y[i]==empId) {
e[i]=e[i+1];
lol=true;
e[i].set_Name();
cin>>redo2;
if(redo2=='Y'||redo2=='y'){
int a;
a=n;
///
goto lebel1;
}
cout <<endl;
//Delete function
}
}
if (lol==false) {
cout<<"Sorry, there is not any employee with requested personal
number."
<<" Do you want to repeat delete by entering the new personal
number (y/n)?:";
cin>>redo1;
if(redo1=='Y'||redo1=='y'){
goto lebel;
cout<<endl<<endl;
}
}
//
//
}
/////////////////////////////////////////////////////////////////////
//
Definition of the UpdatePerson() method of the Company class
//
This method will modify an attribute of the employee in
//
the Company class instance. The employee and attribute should be
//
ones of the user's own choosing.
void HRM::UpdatePerson(){
int empId;
char redo1,redo2;
lebel:
cout << "ID of employee to modify data: ";
while(!(cin>>empId)) //Reciving vaiables from input : is it
no/character ?
{
cout << "Please enter a number! Try again: ";
cin.clear ();
cin.ignore (1000, '\n'); // Skip to next newline or 1000
chars,
// whichever comes first.
}
int flag1=0;
for (int i = 0; i < n; ++i) {
if (y[i]!=empId) {
flag1++;
}
}
/*
if (flag1==n){
// cout<<" not
matching="<< y[i];
if (y[i]==empId) {
cout<<"matching="<< y[i];
flag=true;
int choice = 0;
char redo;
do {
cout << endl << endl;
cout << "Please enter the related number of field which you
would like to update" << endl;
cout <<"1. First name" << endl;
cout << "2. Family name" << endl;
cout << "3. Working hours per week" << endl;
cout << "4. Payment for one hour" << endl;
cout << std::endl;
cin >> choice;
if (choice == 1) {
cout << " First name: ";
e[i].in_FirstName();
}
else if (choice == 2) {
cout << " Family name: ";
e[i].in_FamilyName();
}
else if (choice == 3) {
cout << " Working hours per week: ";
e[i].in_Workinghour();
}
else if (choice == 4) {
cout << " Payment for one hour: ";
e[i].in_Costperhour();
}
cout<<"Do you want to update another field (Y/N)=";
cin>>redo;
} while (redo=='y'||redo=='Y');
}
}
int a;
a=n;
cout<<"\nThe employee with the following information has been added
to the system:"<<endl;
cout<<"\nFirst Name
Last Name
Personal ID
Salary
per year (Euros)";
cout<<"\n--------------------------- ------------------------------------"<<endl;
for(int i=0; i<a; i++){
e[i].get_FieldName();
cout<<"hahahahah="<<n<<endl;
}
}
void ::Person::in_FirstName()
{
cin>>FirstName ;
}
void::Person::in_FamilyName()
{
cin>>LastName;
}
void::Person::in_Workinghour()
{
cin>>WorkingHours;
Salary=WorkingHours*CostPerHour*52;
}
void::Person::in_Costperhour()
{
cin>>CostPerHour;
Salary=WorkingHours*CostPerHour*52;
}
void HRM::ReportList() {
char op;
bool doMore;
cout<<"\nPlease enter the related number of the field which you would like to
sort the list based on it.\n(1. Family name, 2.Salary)?\n"<<endl;
//cin>>op;
while(!(cin>>op)) //Reciving vaiables from input : is it no/character ?
{
cout << "Please enter a number! Try again: ";
cin.clear ();
cin.ignore (1000, '\n'); // Skip to next newline or 1000
chars,
// whichever comes first.
}
switch(op)
{
case '1':
cout<<"\nSorting based on Family Name\n"<<endl;
for(int i=0;i<=n;i++)
{
for(int j=i+1;j<=n-1;j++)
{
if(h[i]>h[i+1])
{
temp[i]=e[i];
e[i]=e[j];
e[j]=temp[i];
}
}
}
for(int i=0;i<n;i++)
{
e[i].get_FieldName();
}
cout<<"\nsorted\n";
break;
case'2':
cout<<"\nSorting based on Salary\n"<<endl;
for(int h=0;h<n;h++)
{
for(int q=h+1;q<n;q++)
{
if(sal[h]>sal[h+1]);
{
temp[h]=e[h];
e[h]=e[q];
e[q]=temp[h];
}
}
}
for(int j=0;j<n;j++)
{
e[j].get_FieldName();
}
cout<<"\nsortedlist is printed above\n";
break;
}
}
void HRM::SearchPerson(){
int c;
char redo1;
string familyname;
double min,max;
do{
cout<<"Search is based on two different fields (1.family name,
2.Salary), please enter your choice?="<<endl;
//cin>>c;
while(!(cin>>c)) //Reciving vaiables from input : is it
no/character ?
{
cout << "Please enter a number! Try again: ";
cin.clear ();
chars,
// whichever comes first.
}
if(c==2)
{
cout<<"Please define your search range for salary of
employees ."<<endl;
cout<<"What is minimum salary for search (S_min)?="<<endl;
//cin>>min;
while(!(cin>>min)) //Reciving vaiables from input : is it
no/character ?
{
cout << "Please enter a number! Try again: ";
cin.clear ();
cin.ignore (1000, '\n'); // Skip to next newline or 1000
chars,
// whichever comes first.
}
cout<<"What is maximum salary for search (S_max)?="<<endl;
//cin>>max;
while(!(cin>>max)) //Reciving vaiables from input : is it
no/character ?
{
cout << "Please enter a number! Try again: ";
cin.clear ();
cin.ignore (1000, '\n'); // Skip to next newline or 1000
chars,
// whichever comes first.
}
int a;
a=n;
cout<<"\nThe employee with the following information has been added
to the system:"<<endl;
cout<<"\nFirst Name
Last Name
Personal ID
Salary per year
(Euros)";
cout<<"\n--------------------------- ------------------------------------"<<endl;
for(int i=0; i<n; i++) {
cout<<"naaaaaaaaaaaam"<< n<<endl;
e[i].gett_FieldName();
cout<<"matching="<< z[i];
}
}
}
else if(c==1)
{
cout<<"Please enter the family name of employee?"<<endl;
cin>>familyname;
cout<<"\nThe employee with the following information has
been added to the system:"<<endl;
cout<<"\nFirst Name
Last Name
Personal ID
Salary per year (Euros)";
cout<<"\n--------------------------- ------------------------------------"<<endl;
for(int i=0; i<n; i++) {
if (h[i]==familyname) {
cout<<"naaaaaaaaaaaam"<< n<<endl;
e[i].gett_FieldName();
cout<<"matching="<< z[i];
}
}
}
cout<<"\nDo you want to Search any other field (y/n)?\n"<<endl;
cin>>redo1;
}while(redo1=='y'||redo1=='Y');
void ::Person::LastNamesortList() {
int temp2;
char temp,temp1;
}
void::Person ::set_Name(){
cout<<"Do you really want to delete
employee"<<FirstName<<"\t"<< LastName<< "(y/n)?:";
}
//PersonalID=y[i];
int k=0;
void::Person ::set_FieldName(){
PersonalID=x;
x++;
cout<<n;
cout<<"First Name=";
while(!(cin>>FirstName)) //Reciving vaiables from input : is it
no/character ?
{
cout << "Please enter a string! Try again: ";
cin.clear ();
cin.ignore (1000, '\n'); // Skip to next newline or 1000
chars,
// whichever comes first.
}
cout<<"Last Name=";
while(!(cin>>LastName)) //Reciving vaiables from input : is it
no/character ?
{
cout << "Please enter a string! Try again: ";
cin.clear ();
cin.ignore (1000, '\n'); // Skip to next newline or 1000
chars,
// whichever comes first.
}
cout<<"How many hours a week is his/her work? =";
;
while(!(cin>>WorkingHours)) //Reciving vaiables from input : is it
no/character ?
{
cout << "Please enter a number! Try again: ";
cin.clear ();
cin.ignore (1000, '\n'); // Skip to next newline or 1000
chars,
// whichever comes first.
}
cout<<"How much per hour is his/her salary? =";
while(!(cin>>CostPerHour)) //Reciving vaiables from input : is it
no/character ?
{
cout << "Please enter a number! Try again: ";
cin.clear ();
cin.ignore (1000, '\n'); // Skip to next newline or 1000
chars,
// whichever comes first.
}
Salary=WorkingHours*CostPerHour*52;
z[i]= Salary;
sal[i]=Salary;
h[i]=LastName;
y[k]=PersonalID;
k++;
}
void::Person ::get_FieldName(){
cout<<FirstName<<"\t\t"<<LastName<<"\t\t\t"<<PersonalID<<"\t\t\t"<<Salary<<"\t
"<<endl;
}
void::Person ::gett_FieldName(){
cout<<FirstName<<"\t\t"<<LastName<<"\t\t\t"<<PersonalID<<"\t\t\t"<<Salary<<"\t
"<<endl;
}
int main()
{
//-------defining variables and initializing them-------------
HRM info ;
int c;
char operation,ch;
//--------Printing my name on screen---------------cout<<
"Welcome to the program 2.1 written by Your Name"<<endl;
cout<<"***********************************************************************
***"<<endl;
cout<<endl<<endl<<endl;
do
{
cout<<"Welcome to Human Resource Management (HRM) Software of Company
XYZ.";
cout<<"To do specific task please choose one of the following
commands."<<endl<<endl<<endl;
cout<<"
1. Add new employee"<<endl;
cout<<"
2. Delete employee information"<<endl;
cout<<"
3. Update employee information"<<endl;
cout<<"
4. Make reports based on specific field"<<endl;
cout<<"
5. Search employee"<<endl;
cout<<"
6. Quit"<<endl<<endl;
system("pause");
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------