programming with link list

I have this program where I have to do the following:

1) Your task is to write a program which reads Employees data and processes the data.

2) You have to create a class named EmployeeLinkedList which defines the linked list that has the EmployeeNode class as its nodes.

EmployeeNode class

Data members:

Employee Emp;

EmployeeNode* next;

Public members:

- The node constructor.


EmployeeLinkedList class

Data members:

EmployeeNode* head;

Public members:

- The constratuctor that initiates your list to Null.

- The destructor of your linked list. Make sure that you delete all the linked list nodes.

- The insert function. Your function have to take care of different insertion cases.(i.e. if your linked list is empty, insertion in the middle, insertion at the end)

- The delete function. This function deletes a specified node from your list.

- The function that print the linked list.

3) Write a test program.

* In the main function,
o Open the input file called input.txt, and read the employees data.
o Create a node for each employee and insert it in your linked list. Make sure that you are inserting it such that the linked list is ascending-ordered according to the first name.

* Processing the data.

Your program should display a menu (as below) to the user that allows him to:

I --- Insert new Employee

S --- Search the list for an employee.

D --- Delete an employee from the list.

P --- Print the list of the employees.

E --- Exit the program

Please enter your choice: _

o For I, read the Employee information from the keyboard and insert it at the right place in your ordered list.
o For S, read the employee first name form the keyboard, search your list for the first occurrence of it. If you find it display the rest of the information at the screen. If it is not in the list display The Employee does not exist.

o For D, your program should do the following:

1- Your program should ask the user to enter the employee first name.

2- Your program has to search for the given employee and delete it from the list. And confirm back to the user by printing the message: The employee EmployeeFirstName has been deleted.

3- If the employee is not in your list, print The Employee EmployeeFirstName does not exist.

o For P, print the list of all Employees.
o For E, exit from your program. Your program should not stop running unless the user chooses E to Exit.

I need help on writing this program

here is what I have so far
#include "EmployeeLinkedList.h"
using namespace std;

int EmployeeLinkedList::count = 0;

void EmployeeLinkedList::insert(const Employee& anEmp, int where){
int size = 15;
EmployeeNode *prev = new EmployeeNode(anEmp);
EmployeeNode *cur = new EmployeeNode(anEmp);

assert(where>=0 && where <= size);
if(where == 0){//inserting at front
cur = head;
head = new EmployeeNode(anEmp);
head->next = cur;

prev = NULL;
cur = head;
prev = new EmployeeNode(anEmp);
cur = new EmployeeNode(anEmp);
prev = cur;
cur = cur->next;

prev->next = new EmployeeNode(anEmp);

void EmployeeLinkedList::remove(int pos){
EmployeeNode *cur, *prev;
assert(pos>=0 && pos0){
prev = cur;
cur = cur->next;
prev->next = cur->next;
delete cur;

int EmployeeLinkedList::getCount() const {
return count;

void EmployeeLinkedList::addEmployee(Employee e) {
assert(count < MAX-1);
employees[count++] = e;


bool EmployeeLinkedList::findEmployee(string fName) {
for(int i = 0;i employees[j].getName().getFirstName())//gets the first name of employees[i] and compares it to employees[j]
swap(employees[i],employees[j]);//swaps employees[i] with employees[j] if employees[i]>employees[j]

void EmployeeLinkedList::swap(Employee& one, Employee& two){
Employee temp;
one = two;
two = temp;


void EmployeeLinkedList::print() const {
for(int i = 0; i<count;i++){
Name tmpname = employees[i].getName();
cout<<tmpname.getFirstName()<<" "<<tmpname.getMiddleInitial()<<" "<<tmpname.getLastName()<<" ";//prints out first, middle initial, and last name to screen

Address tmpaddress = employees[i].getAddress();
cout<< tmpaddress.getStreet()<<" "<<tmpaddress.getCity()<<" "<<tmpaddress.getState()<<" "<<tmpaddress.getZipCode()<<endl;//prints out street, city, state,and zipcode to screen

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion