Question
In the below code Add a main menu to manage the employees data, which will include a choice of: 1) Access employee record based on
In the below code Add a main menu to manage the employees data, which will include a choice of: 1) Access employee record based on employee ID only (can be the index of the array, you may not to perform a search, this is called Hashing 2) Add an employee to the database 3) Delete an employee (delete the index), if an ID is available use it for the new employee
#include
// Employee Class Declaration
class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position
public: // Constructors Employee(string, int, string, string); Employee();
// update methods void setName(string n) { name = n; }
void setIdNumber(int i) { idNumber = i; }
void setDepartment(string d) { department = d; }
void setPosition(string p) { position = p; }
// Accessors string getName() { return name; }
int getIdNumber() { return idNumber; }
string getDepartment() { return department; }
string getPosition() { return position; } };
// Constructor #1 Employee::Employee(string n, int i, string d, string p) { name = n; idNumber = i; department = d; position = p; }
// Constructor #3, default constructor Employee::Employee() { name = ""; idNumber = 0; department = ""; position = ""; }
// Function prototype void displayEmployee(Employee); void addEmployee(Employee*, int&); void deleteEmployee(Employee*, int&); void searchEmployee(Employee*, int);
// Driver program to demonstrate the class int main() { // Create an Employee object based on the current constructor. Employee Albert("Albert Smith", 1, "Executive", "President");
int choice; do { cout << "Main Menu" << endl; cout << "1. Access Employee Record" << endl; cout << "2. Add Employee" << endl; cout << "3. Delete Employee" << endl; cout << "4. Quit" << endl; cout& #8203; `oaicite:{"index":0, "invalid_reason" : "Malformed citation << \"Enter your choice: \"; cin >>"}` choice;
switch (choice) { case 1: searchEmployee(employees, numOfEmployees); break; case 2: addEmployee(employees, numOfEmployees); break; case 3: deleteEmployee(employees, numOfEmployees); break; case 4: break; default: cout << "Invalid choice, try again." << endl; break; }
} while (choice != 4);
return 0; }
void displayEmployee(Employee e)
Employee employees[10];
// Display each employee's data. displayEmployee(Albert); displayEmployee(employees[2]);
return 0; }
//************************************************** // The displayEmployee function displays the data * // in the Employee object passed as an argument. * //**************************************************
void displayEmployee(Employee e) { cout << "Name: " << e.getName() << endl; cout << "ID Number: " << e.getIdNumber() << endl; cout << "Department: " << e.getDepartment() << endl; cout << "Position: " << e.getPosition() << endl << endl; }
void mainMenu() { int choice;
cout << "Main Menu" << endl; cout << "1. Access Employee Record" << endl; cout << "2. Add Employee to the Database" << endl; cout << "3. Delete Employee" << endl; cout& #8203; `oaicite:{"index":0, "invalid_reason" : "Malformed citation << \"Enter your choice: \"; cin >>"}` choice;
switch (choice) { case
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started