You are on page 1of 2

Structs & Pointers (with FILE IO)

Mini-Project: Maintain Employee Records (Double-Linked List) in Files


This main objective of this project is to learn the various operations in a Linked List data structure &
learn how to preserve the data values in files.
(create linked list, add/delete/search/edit nodes, save node values in files, reload values on restart)

NOTE: This is the same project that was done in the “Structs & Pointers” module. You are
expected to now update this project to achieve data persistence across run cycles. In other
words, you are expected to implement File IO operations in this project. This can be
achieved by saving the values of each node (as a record) in a file, and reading these values
back again when the program is re-started so that all previous node’s values should still be
available across each runs of the program.
=====================
***** Main Menu *****
=====================
1. Add Node
2. Delete Node
3. Search Node
4. Display List
5. Cleanup (Delete all nodes)
6. EXIT
Enter your option (1..6) : __

The program should display the above menu, and perform these operations in order to main records of
various employees in an organization.

Design considerations:

1. The program should use a struct EMP defined as follows –

struct EMP
{
string emp_name;
int emp_id;

EMP *next, *prev;


};

2. The program should define two global variables, head and tail, representing pointers to the first and
the last node in the linked list at any point of time.

EMP *head = NULL;


EMP *tail = NULL;

3. The program should use user-defined functions to perform each of the functions in the above menu.

4. The prototypes of the functions should be as specified in the table (see next page).

Author: Manoj Jauhari Unix C & C++ Mini-Project

Sensitiv ity: Internal & Restricted


Structs & Pointers (with FILE IO)
Function Prototype Return values
int addNode(); // returns 1 or 2 1 – Head node added
2 – Non-head node added
int deleteNode(); // returns 0, 1, 2 or 3 0 – Node to be deleted NOT FOUND
int deleteThisNode(EMP*); // returns 1, 2 or 3 1 – deleted head node
2 – deleted one of the middle nodes
Note: The function deleteNode() should prompt the user to enter 3 – deleted tail node
the emp_id of the employee record to be deleted. The function
should traverse the list to search the node which matches the
specified emp_id. If the emp_id is not found, the function should
return 0. If the node with matching emp_id is found, the function
should invoke “int deleteThisNode(EMP*)” function that should do
the task of actually deleting the node, and return appropriate
return value 1, 2 or 3 as specified in the “Return Values” column.
int searchNode(); // return 0 or 1 0 – Node not found
1 – Node found and contents displayed
This function should prompt the user to enter the emp_id of the
record to be searched. It should then search the list based on the
specified emp_id and accordingly display the contents of the node
that matches the emp_id.
void dispalyList(); // No return value No return values.

This function should display the contents of all the nodes in the
linked list. It should start with the title -

LINKED LIST DISPLAY


===================
EMP Name =
EMP id =

EMP Name =
EMP id =

. . . and then display the contents (emp_name and emp_id) of all


the nodes in the list.
void cleanup(); // No return value No return values.

This function should delete (deallocate memory for) all the nodes
in the list.

If the menu option 5 is chosen, the cleanup() function should


delete all the nodes in the list and make the ground ready for
adding a new set of nodes from the beginning.

If the menu option 6 is chosen, the program is expected to exit.


However, before exiting, the program should call the cleanup()
function to deallocate the allocated memory.

Author: Manoj Jauhari Unix C & C++ Mini-Project

Sensitiv ity: Internal & Restricted

You might also like