Currently having trouble completing my code homework for my class. Help would be greatly appreciated.
Write a menu-driven C++ program to manage employee data. Your program should begin by reading in a file of employee information (filename employdata.txt). Each data line contains the following information:
{hire date} {employee ID} {salary}
Note that all data values can be stored as integers. The dates included are integers but in a strict format: yyyymmdd. Read these data values into three parallel arrays for further processing.
Write a menu-driven program that offers the user the following options.
•List by hire date
•List by employee number
•Write total of salaries
•Add employee
•Delete employee
The "list" functions imply sorting the arrays either by hire date or employee number and then writing the entire data set. Be sure that it is written in an organized and readable format. The function to add an employee requires prompting for a new element for all three arrays. Be sure the elements are added and kept in "parallel" format. For the function to delete an element, prompt the user for an employee number and then delete that element from all three arrays.
Be sure to consider modularity in this program. Obvious functions to implement include the displaying the menu, adding and deleting an employee, as well as the sorting/display actions.
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void GetList(ifstream& fileIn, int hiredate[], int employee[], int salary[],
int& totalRecs);
void menuaction (int hiredate[], int employee[], int salary[], int totalRecs);
void DisplayList( int hiredate[], int employee[], int salary[], int totalRecs);
void swap(int& hiredate, int& employee);
int sum(int salary[]);
void UnOrdInsert(int list[], int& numElems, int newint);
void UnOrdDelete(int list[], int& numElems, int oldint);
const int MAX_LIST_SIZE = 25;
int main()
{
// Set up file
ifstream fileIn;
InFile.open("employdata.txt"); //Open The File
if (fileIn.fail() ) // Test for file existence
{
cout << "Problem opening file";
exit(-1);
}
// Array of list elements
int listSize;
int hiredate[MAX_LIST_SIZE];
int employee[MAX_LIST_SIZE];
int salary[MAX_LIST_SIZE];
int totalRecs[MAX_LIST_SIZE];
ifstream theData;
GetList(InFile, hiredate, employee, salary, totalRecs);
menuaction (hiredate, employee, salary, totalRecs);
}
/**********************************************************************
// This function reads integers from a file and stores the values in //
// an array. It returns the loaded array and the number of elements //
// in the array //
**********************************************************************/
void GetList(ifstream& InFile, int hiredate[], int employee[], int salary[], int totalRecs )
{
int i;
i = 0;
// Priming read
InFile >> hiredate[i] >> employee[i] >> salary[i];
while( ! theData.eof() )
{
i++; // Add one to pointer
// continuation reads
inFile >> hiredate[i] >> employee[i] >> salary[i];
}
// Capture final index pointer as number of elements (one index past last good element)
totalRecs = i;
return 0;
}
/********************************************************
* This function is the Menu action for the program *
* *
********************************************************/
void menuaction (int hiredate[], int employee[], int salary[], int totalRecs);
{
int choice;
do
{
cout << "\n\t\tEmployee Data Menu\n\n";
cout << "1. List by hiredate\n";
cout << "2. List by employee number\n";
cout << "3. Write total of salaries\n";
cout << "4. Add employee\n\n";
cout << "5. Delete employee\n\n";
cout << "6. TERMINATE SESSION\n\n";
cout << "Enter your choice: ";
cin >> choice;
if (choice >= 1 && choice <= 5)
{
switch (choice)
{
case 1: DisplayList(hiredate, employee, salary, totalRecs);
break;
case 2: swap(hiredate, employee);
DisplayList(hiredate, employee, salary, totalRecs);
break;
case 3: sum(salary);
DisplayList(hiredate, employee, salary, totalRecs);
break;
case 4: UnOrdInsert(list, numElems, newint);
DisplayList(hiredate, employee, salary, totalRecs);
break;
case 5: UnOrdDelete(list, inumElems, oldint)
break;
case 6: return 0;
break;
}
}
else if (choice != 6)
{
cout << "The valid choices are 1 through 6.\n";
cout << "Please try again.\n";
}
} while (choice != 6);
return 0;
}
/******************************************************************/
/* This function writes a list to console output: one list */
/* item at a time because the file was wrote in date order already*/
/******************************************************************/
void DisplayList( int hiredate[], int employee[], int salary[],int totalRecs)
{
for (int i = 0;i < listsize; i++)
cout << hiredate[i], employee[i], salary[i] << " ";
cout << endl;
}
/***************************************************************
/ This functions Lists the employees by number *
/***************************************************************/
void swap(int& hiredate[], int& employee[])
{
int blank[] = hiredate[];
hiredate[] = employee[];
employee[] = blank[];
}
}
/***************************************************************
/ This functions writes the total of the salaries *
/***************************************************************/
int sum(int salary[]) // Function Definition
{
int total=0;
for(int i = 0; i <= (!theData.eof()); i++)
{
total += salary[i];
}
return total;
}
/************************************************************/
/* This function receives an integer, an array containing */
/* an unordered list, and the size of the list. It inserts */
/* a new integer item at the end of the list. */
/************************************************************/
void UnOrdInsert(int list[], int& numElems, int newint)
{
cout << "Insert New Employee HIREDATE:" << endl;
cin >> hiredate >> endl;
cout << "Insert New Employee ID NUMBER:" << endl;
cin >> employee >> endl;
cout << "Insert New Employee's Salary:" << endl;
cin >> salary >> endl;
list[numElems] = newint; // Insert new element at end of list
numElems++; // Increment size of list
}
/************************************************************/
/* This function receives an integer, an array containing */
/* an unordered list, and the size of the list. It locates */
/* and deletes the integer integer from the list. */
/************************************************************/
void UnOrdDelete(int list[], int& numElems, int oldint)
{
int ptr = 0; // Scan list for deletion target
while (oldint != list[ptr] && ptr < numElems)
ptr++;
if (ptr < numElems) // If target found, then
{
list[ptr] = list[numElems-1]; // Last list item to overwrite target
numElems--; // Decrement size of list
}