Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

programming with link list

garyjrthegreatgaryjrthegreat Posts: 1Member
I have this program where I have to do the following:
Description:

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"
#include
#include
#include
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);
size++;
if(where == 0){//inserting at front
cur = head;
head = new EmployeeNode(anEmp);
head->next = cur;
cout<<"Hi"<<endl;
}

else
prev = NULL;
cur = head;
while(where>0){
prev = new EmployeeNode(anEmp);
cur = new EmployeeNode(anEmp);
prev = cur;
cur = cur->next;
where--;
cout<<"bye"<<endl;
}

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

void EmployeeLinkedList::remove(int pos){
EmployeeNode *cur, *prev;
assert(pos>=0 && pos0){
prev = cur;
cur = cur->next;
pos--;
}
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;
temp=one;
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.