Saturday, June 30, 2012

Vector Operations in C++ -- Part 3

In the last post, we implemented the searching procedure followed in the Employee Register. Now we will discuss the CRUD operations on the vector with Employee class.

To go to the previous two posts,
Vector Operations in C++ -- Part 1 and
Vector Operations in C++ -- Part 2

For adding an employee, we need to first check if another employee of the same employee ID exists in the vector. If it exists, we should give the relevant message to the user. Since we know that adding or deleting the employees at the ends is done very quickly, we have used the function "push_back" to add the new employee to the end.



For displaying the employee details, we must first check if the vector is empty. If it is empty, we need not traverse through the vector.



For deleting and updating an employee details, we need to check if the employee with the given ID exists. If it does not exist, the relevant message must be displayed.



Till now we have done all the operations required for manipulating or displaying the employee data. But a good user interface which is easily understandable by the user is equally important. Thus, we will have a menu with all the above discussed operations. To take numerical and string input from the user, we use two member functions in the class "EmployeeDisplay". Validation to the complete extent is not done for numerical and string inputs.

Compiling and running the case study:

Compiling:
g++ -o EmployeeRegister main.cpp Display.cpp Employee.cpp EmployeeRegister.cpp
Running the executable:
./EmployeeRegister

Sample Output for an add operation in the following menu is given below.



I have uploaded the entire project at the following link: Vector Operations Case Study. You can download the "Employee Register.zip" from this link.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...