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 
  }

I would suggest debugging your code. You can then see where you go wrong. There are many mistakes regarding arrays, I would suggest you read some material on how they work. Also, your swap function does no sorting at all. In fact I don't think it even swaps the data, though I have not tested it. You need to look up sorting algorithms and find one that is easy enough to implement and yet fits your problem.

I would suggest debugging your code. You can then see where you go wrong. There are many mistakes regarding arrays, I would suggest you read some material on how they work. Also, your swap function does no sorting at all. In fact I don't think it even swaps the data, though I have not tested it. You need to look up sorting algorithms and find one that is easy enough to implement and yet fits your problem.

I guess that's why i came to this site to get help understanding the array function, because the book i own for class doesn't explain very well.

Well I went through and debugged a lot of issues out i guess the only issues i have would be formatting and output any insight?

// This program takes a file in and runs a menu driven
// program that processes the data using various 
// functions and arrays
#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 sortarray( int hiredate[], int employee[], int salary[], int totalRecs);
int sum(int salary[]);
void UnOrdInsert(int hiredate[], int employee[], int salary[], int totalRecs); 
void UnOrdDelete(int hiredate[], int employee[], int salary[], int totalRecs);

const int MAX_LIST_SIZE = 25;

int main()
{
// Set up file 
ifstream fileIn; 
fileIn.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, totals; 

GetList(fileIn, 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( ! InFile.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; 

} 
/******************************************************** 
* This function is the Menu action for the program      *
*                                                       *
********************************************************/
void menuaction (int hiredate[], int employee[], int salary[], int totalRecs)
{ 

int choice,totals;

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: sortarray(hiredate, employee, salary, totalRecs);
				DisplayList(hiredate, employee, salary, totalRecs);
				break; 
		case 3: totals=sum(salary);
				DisplayList(hiredate, employee, salary, totalRecs);
				break;
		case 4: UnOrdInsert(hiredate, employee, salary, totalRecs);
				DisplayList(hiredate, employee, salary, totalRecs);
				break;
		case 5: UnOrdDelete(hiredate, employee, salary, totalRecs);
				break;



	} 



} 
else if (choice != 6) 
{ 
cout << "The valid choices are 1 through 6.\n"; 
cout << "Please try again.\n"; 
} 
} 
while (choice != 6); 

} 

/******************************************************************/ 
/* 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 < MAX_LIST_SIZE; i++) 



cout << hiredate[i] << employee[i] << salary[i] << " "; 
cout << endl; 
} 

/***************************************************************
/ This functions Lists the employees by number using sorting   *
/***************************************************************/
void sortarray(int hiredate[], int employee[], int salary[], int totalRecs);
{{
	int temp, end;

	for (end = totalRecs - 1; end>=0; end--)
	{
		for (int count = 0; count < end; count++)
		{ 
			if(hiredate[count] > hiredate[count +1]
			{
				temp = hiredate[count];
				[count] = hiredate[count + 1];
				hiredate[count + 1] = temp;
			}
		}
		for (int count = 0; count < end; count++)
		{ 
			if(employee[count] > employee[count +1]
			{
				temp = employee[count];
				employee[count] = employee[count + 1];
				employee[count + 1] = temp;
			}
		}
		for (int count = 0; count < end; count++)
		{ 
			if(employee[count] > employee[count +1]
			{
				temp = employee[count];
				employee[count] = employee[count + 1];
				employee[count + 1] = temp;
			}
		}
	}

}

/***************************************************************
/ This functions writes the total of the salaries *
/***************************************************************/
int sum(int salary[]) // Function Definition	
{
int total=0;


for(int i = 0; i <= 15; 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 hiredate[], int employee[], int salary[], int totalRecs) 
{
totalRecs++; // Increment size of list

cout << "Insert New Employee HIREDATE:" << endl; 
cin >> hiredate[totalRecs-1];
cout << "Insert New Employee ID NUMBER:" << endl;
cin >> employee[totalRecs-1];
cout << "Insert New Employee's Salary:" << endl;
cin >> salary[totalRecs-1]; 


} 

/************************************************************/ 
/* 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 hiredate[], int employee[], int salary[], int totalRecs) 
{ 
	int empnum = 0,ptr = 0;

cout << " Which employee do you wish to delete" << endl;
cin >> empnum; 

// Scan list for deletion target 
while (empnum != employee[ptr] && ptr < totalRecs) 

ptr++; 

if (ptr < totalRecs) // If target found, then 
{ 
employee[ptr] = employee[totalRecs-1]; // Last list item to overwrite target 
totalRecs--; // Decrement size of list 
}
}

1>.\Pro6final.cpp(35) : warning C4101: 'listSize' : unreferenced local variable
1>.\Pro6final.cpp(39) : warning C4101: 'totals' : unreferenced local variable
1>.\Pro6final.cpp(146) : error C2447: '{' : missing function header (old-style formal list?)
1>.\Pro6final.cpp(241) : fatal error C1004: unexpected end-of-file found
1>Build log was saved at "file://c:\Users\Bobby's Computer\Documents\Visual Studio 2008\Projects\Program 6\Debug\BuildLog.htm"
1>Program 6 - 2 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.