Employee Data Base using Data structures

Hello, I am still fairly new to programming and currently I'm taking a class revolved around data structures using c++. I've been working on a project but have hit a wall in progression in terms of what to do/how to do what I need to do. I'm very willing to learn and am here to accept any help I can get.

The assignment: I need to create a simple employee data base and create functions based off a criteria:

Data-What I deem a structure of an employee that holds the following data, data type were given (ID, Last name, First name, Social security number, salary, and age)

Index- indexes the records using a sort, not moving entire records. Only the primary key and the indexed field should be stored in the program's memory

Display- list of all records in order based on the last indexing. If no index occurs it should display in order of primary key.

Search- Allows user to enter Social Security Number and print a record if it exists.

Add Record- allows user to add record to file. Generate a primary key when this is done. Insure that a new record has a unique SSN and formatted (XXX-XX-XXX)

Delete Record- delete a record

File- store records as a random access file(is this a binary data file). Allows program to access individual records without having to read the whole database in memory.

Menu- Each function will be on a menu that is ran through a queue which allows user to enter all they wish to do at once then the choices will be queued to track the order of requests and executed one after the other. (The menu is the only part of the program I have working at the moment).

DISCLAIMER: Templates are not to be used, my professor likes header files, implementation files, and the main to all be separate from another.

Now that the boring stuff is out of the way I have hit a wall. First being the primary key. It seems this unique number will drive most of the other functions and until I'm able to create one for each employee I won't be able to work on the other functions of the program.

I also have the class Employee which contains all the data, I'm unsure if a linked list is able to be created using a class rather than a structure.

Right now I'm stuck if I'm doing this correctly to make the employee data base or if there's a more effective approach. I'm thinking to create this linked list which holds structures of Employees, if this is in the right direction then do I prototype the accessor/mutator functions here in this class, or should that be done somewhere else?

I assume that I need to use a hash table for primary keys? And to use a hash table I first need to make a linked list of Employee structures that hold data? With that said here is where I am:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*LINKED LIST HEADER FILE*/
#include <iostream>
using namespace std;

//define orderlinklist
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
//create ordered list class
class LinkedList {
	//private memeber varibles
private:
	//create node structure
	struct Employee {
		int idNum,
			age;
		string lastN,
			firstN,
			socSecNum;
		double salary;

		Employee* next;
	};

	//create node structures to allow a list
	Employee* head;
	Employee* curr;
	Employee* temp;

	//public memeber functions
public:
	void printRecord();	//print prototype
	LinkedList();	//default constructor
	void insertRecord();//insert prototype
	void deleteRecord(); 
};
#endif 

Last edited on
you could just use std::vector<Employee> as the program container with employee's SSN as the primary key - that should address the assignment requirements.
in case you want to delve further into the best container for your requirements, take a look here:
http://stackoverflow.com/questions/471432/in-which-scenario-do-i-use-a-particular-stl-container
http://stackoverflow.com/questions/10699265/how-can-i-efficiently-select-a-standard-library-container-in-c11
GunnerFunner, I have since progressed further and instead used class Employee to hold each member variable of the Employee. I do not however know how I could implement the use of
vector<Employee> as a container and make the employee's SSN the primary key. Where would a function like this belong? As part of the Employee Class or Linked List Class? If you'd like to see more parts of my code to see what I'm currently working with please let me know. I'm sorry, I'm still a novice programmer and don't understand the concepts of using a primary key to begin with.
Topic archived. No new replies allowed.