Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

EmployeeManager - employees : Employee[] - employeeMax : final int = 10 -current

ID: 3852892 • Letter: E

Question

EmployeeManager

- employees : Employee[]

- employeeMax : final int = 10

-currentEmployees : int

<<constructor>> EmployeeManager

+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double)

+ removeEmployee( index : int)

+ listAll()

+ listHourly()

+ listSalary()

+ listCommision()

+ resetWeek()

+ calculatePayout() : double

+ getIndex( empNum : int ) : int

+ annualRaises()

+ holidayBonuses() : double

+ increaseHours( index : int, amount : double)

+ increaseSales( index : int, amount : double)

Data Members

-       Employee[] employees – Collection of Employee objects

-       final int employeeMax = 10 – Maximum number of Employees allowed

-       int currentEmployees – Current number of Employees in collection

Methods

public EmployeeManager()

Constructor, creates the Employee array, sets currentEmployees to 0.

public void addEmployee(int, String, String, char, char, int, Boolean, double)

Takes an int representing the type of Employee to be added (1 – Hourly, 2 – Salary, 3 – Commission) as well as the required data to create that Employee. If one of these values is not passed output the line, “Invalid Employee Type, None Added”, and exit the method. If an Employee with the given Employee Number already exists do not add the Employee and output the line, “Duplicate Not Added”, and exit the method. If the array is at maximum capacity do not add the new Employee, and output the line, "Cannot add more Employees".

public void removeEmployee(int)

Removes an Employee located at the given index from the Employee array.

public void listAll()

Lists all the current Employees. Outputs there are none if there are none.

public void listHourly()

Lists all the current HourlyEmployees. Outputs there are none if there are none.

public void listSalary()

Lists all the current SalaryEmployees. Outputs there are none if there are none.

public void listCommission()

Lists all the current CommissionEmployees. Outputs there are none if there are none.

public void resetWeek()

Resets the week for all Employees.

public double calculatePayout()

Returns the total weekly payout for all Employees.

public int getIndex(int)

Given an Employee Number, returns the index of that Employee in the array, if the Employee doesn’t exist retuns -1.

public void annualRaises()

Applies annual raise to all current Employees.

public double holidayBonuses()

Outputs and returns the total holiday bonus of all Employees.

public void increaseHours(int, double)

Increase the hours worked of the Employee at the given index by the given double amount.

public void increaseSales(int, double)

Increase the sales of the Employee at the given index by the given double amount.

Some notes:

·         To begin with the EmployeeManager has no Employees

·         There should never be two Employees with the same number, the newer Employee would be removed

EmployeeManager

- employees : Employee[]

- employeeMax : final int = 10

-currentEmployees : int

<<constructor>> EmployeeManager

+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double)

+ removeEmployee( index : int)

+ listAll()

+ listHourly()

+ listSalary()

+ listCommision()

+ resetWeek()

+ calculatePayout() : double

+ getIndex( empNum : int ) : int

+ annualRaises()

+ holidayBonuses() : double

+ increaseHours( index : int, amount : double)

+ increaseSales( index : int, amount : double)

Explanation / Answer

This question includes multiple sub-questions so only answering those which I found mandatory.

#include<iostrem.h>
#include<conio.h>
#include<fstream.h>
#include<stdlib.h>
#include<iomanip.h>
#include<string.h>
#include<stdio.h>
const char* fileName=”Employee.txt”;

Class Employee
{
   private;
   int EmpID;
   char EmpName[50],Post[50],Department[10];
   float Salary;
   public;
   void ReadData();
   int GetID();
   void DisplayRecord();
   char* GetDepartment();
};

void Employee::ReadData()
{
   cout<<endl<<“Employee ID:”;
   cin>>EmpID;
   cout<<“Employee Name:”;
   cin>>EmpName;
   cout<<“Employee’s Post:”;
   cin>>Post;
   cout<<“Employee’s Department:”;
   cin>>Department;
   cout<<“Salary:”;
   cin>>Salary;
}

void Employee::DisplayRecord()
{
   cout<<endl<<“_______________________________”;
   cout<<endl<<setw(5)<<EmpID<<setw(15)<<EmpName<<setw(15)<<Post<<setw(15)<<Department<<setw(8)<<Salary;
}

int Employee::GetID()
{
   return EmpID;
}

char* Employee::GetDepartment()
{
   return Department;
}

void main()
{
   Employee emp,e;
   char option,ch,Dept[50];
   int ID,isFound;
   clrscr();
   fstream file;
   file.open(fileName,ios::ate|ios::in|ios::out|ios::binary);
   do
{
   cout<<********Menu********;
   cout<<endl<<“Enter your option”;
   cout<<endl<<“1 => Add a new record”;
   cout<<endl<<“2 => Search record from employee id”;
   cout<<endl<<“3 => List Employee of particular department”;
   cout<<endl<<“4 => Display all employee”;
   cout<<endl<<“5 => Update record of an employee”;
   cout<<endl<<“6 => Delete record of particular employee”;
   cout<<endl<<“7 => Exit from the program”<<endl;
   cout<<“********************”<<endl;
   cin>>option;
   switch(option)
       {
       case ‘1’:
       emp.ReadData();
       file.seekg(0,ios::beg);
       isFound=0;
       file.read((char*)&e,sizeof(e));
       while(!file.eof())
           {
               if(e.GetID()==emp.GetID())
                   {
                       cout<<“This ID already exist…Try for another ID”;
                       isFound=1;
                       break;
                   }
                       file.read((char*)&e,sizeof(e));
           }  
               if(isFound==1)
               break;
               file.clear();
               file.seekp(0,ios::end);
               file.write((char*)&emp, sizeof(emp));
               cout<<endl<<“New record has been added successfully…”;
               break;

               case ‘2’:
               isFound=0;
               cout<<endl<<“Enter ID of an employee to be searched:”;
               cin>>ID;
               file.seekg(0,ios::beg);
               file.read((char*)&e,sizeof(e));
               while(!file.eof())
               {
                   if(e.GetID()==ID)
                   {
                       cout<<endl<<“The record found….”<<endl;
                       cout<<endl<<setw(5)<<“ID”<<setw(15)<<“Name”<<setw(15)<<“Post”<<setw(15)<<“Department”<<setw(8)<<“Salary”;
                       e.DisplayRecord();
                       isFound=1;
                       break;
                   }
                       file.read((char*)&e,sizeof(e));
               }
               file.clear();
               if(isFound==0)
               cout<<endl<<“Data not found for employee ID#”<<ID;
               break;
               case ‘3’:
               isFound=0;
               cout<<“Enter department name to list employee within it:”;
               cin>>Dept;
               file.seekg(0,ios::beg);
               file.read((char*)&e,sizeof(e));
               while(!file.eof())
               {
                   if(strcmp(e.GetDepartment(),Dept)==0)
                       {
                           cout<<endl<<“The record found for this department”<<endl;

                           cout<<endl<<setw(5)<<“ID”<<setw(15)<<“Name”<<setw(15)<<“Post”<<setw(15)<<“Department”<<setw(8)<<“Salary”;
                           e.DisplayRecord();
                           isFound=1;
                           break;
                       }
                           file.read((char*)&e,sizeof(e));
               }
               file.clear();
               if(isFound==0)
               cout<<endl<<“Data not found for department”<<Dept;  
               break;

               case ‘4’:
               cout<<endl<<“Record for employee”;
               file.clear();
               file.seekg(0,ios::beg);
               int counter=0;
               file.read((char*)&e,sizeof(e));
               while(!file.eof())
               {
               counter++;
               if(counter==1)
                   {
                       cout<<endl<<setw(5)<<“ID”<<setw(15)<<“Name”<<setw(15)<<“Post”<<setw(15)<<“Department”<<setw(8)<<“Salary”;
                   }
                   e.DisplayRecord();
                   file.read((char*)&e,sizeof(e));
                       }
                   cout<<endl<<counter<<“records found……”;
                   file.clear();
                   break;

               case ‘5’:
               int recordNo=0;
               cout<<endl<<“File is being modified….”;
               cout<<endl<<“Enter employee ID to be updated:”;
               cin>>ID;
               isFound=0;
               file.seekg(0,ios::beg);
               file.read((char*)&e,sizeof(e));
               while(!file.eof())
               {
               recordNo++;
               if(e.GetID()==ID)
               {
                   cout<<“The old record of employee having ID”<<ID<< “is:”;
                   e.DisplayRecord();
                   isFound=1;
                   break;
               }
                   file.read((char*)&e,sizeof());
               }

               if(idFound==0)
               {
                   cout<<endl<<“Data not found for employee ID#”<<ID;
                   break;
               }
               file.clear();
               int location=(recordNo-1)*sizeof(e);
               file.seekp(location,ios::beg);
               cout<<endl<<“Enter new record for employee having ID”<<ID;
               e.ReadData();
               file.write((char*)&e, sizeof(e));
               break;

               case ‘6’:
                   recordNo=0;
                   cout<<endl<<“Enter employment ID to be deleted:”;
                   cin>>ID;
                   isFound=0;
                   file.seekg(0,ios::beg);
                   file.read((char*)&e,sizeof(e));
                   while(!file.eof())
                   {
                   recordNo++;
                   if(e.GetID()==ID)
                   {
                   cout<<” The old record of employee having ID “<<ID<< ” is: “;
                   e.DisplayRecord();
                   isFound=1;
                   break;
                   }
                   file.read((char*)&e,sizeof(e));
                   }
                   char tempFile[]=”temp.txt”;
                   fstream temp(tempFile,ios::out|ios::binary);
                   if(isFound==0)
                   {
                   cout<<endl<<“Data not found for employee ID#”<<ID;
                   break;
                   }
                   else
                   {
                   file.clear();
                   file.seekg(0,ios::beg);
                   file.read((char*)&e,sizeof(e));
                   while(!file.eof())
                   {
                   if(eGetID()!=ID)
                   temp.write((char*)&e,sizeof(e));
                   file.read((char*)&e,sizeof(e));
                   }
                   file.close();
                   temp.close();
                   temp.open(tempFile,ios::in|ios::binary);
                   file.open(fileName,ios::out|ios::binary);
                   temp.read((char*)&e,sizeof(e));
                   while(!temp.eof())
                   {
                   file.write((char*)&e,sizeof(e));
                   temp.read((char*)&e,sizeof(e));
                   }
                   }
                   temp.close();
                   file.close();
                   remove(tempFile);
                   file.open(fileName,ios::ate|ios::in|ios::out|ios::binary);
                   break;

                   case ‘7’:
                   exit(0);
                   break;

                   default:
                   cout<<“Invalid Options”;
                   }
                   cout<<“ Do you want to continue…..?y/n”;
                   cin>>ch;
                   }while(ch!=’n’);
                   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote