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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
# include <iostream>
# include <fstream>
# include <cmath>
using namespace std;
const int MAX_ARRAY = 50;
void getdata(int &numElem, int hireDate[], int empID[], double salary[], ifstream &fileIn);
void showMenu();
void ListHD(int numElem,int array[], int hireDate[], int empID[], double salary[]);
int main()
{
ifstream fileIn;
int hireDate[MAX_ARRAY]; //Array's for storage of hiredate, employee id, and salary
int empID[MAX_ARRAY];
double salary[MAX_ARRAY];
int numElem;
fileIn.open("employdata.txt"); //Open file
if (fileIn.fail()) //test file for existance
{
cout << "Problem with file";
exit(-1);
}
getdata(numElem, hireDate, empID, salary, fileIn); //Read file and count values into 3 paralell arrays
showMenu();
ListHD(numElem, hireDate, empID, salary);
system("pause");
}
void getdata(int &numElem, int hireDate[], int empID[], double salary[], ifstream &fileIn)
{
int i = 0;
fileIn >> hireDate[i] >> empID[i] >> salary[i];
while (!fileIn.eof())
{
i++;
fileIn >> hireDate[i] >> empID[i] >> salary[i];
}
numElem = i;
//for (int i = 0; i < numElem; i++)
//cout << hireDate[i] << " " << empID[i] << " " << salary[i] << endl;
}
void showMenu()
{
cout << "\n\t\tEmployee data menu\n\n"
<< "1. List by hire date\n"
<< "2. List by employee number\n"
<< "3. Write total of salaries\n"
<< "4. Add employee\n"
<< "5. Delete employee\n"
<< "6. Quit Program\n"
<< "Please enter a valid menu choice: \n";
}
void ListHD(int numElem, int array[], int hireDate[], int empID[], double salary[])
{
int temp, end;
for (end = numElem - 1; end >= 0; end--)
{
for (int count = 0; count < end; count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
}
}
}
for (int i = 0; i < numElem; i++)
cout << array[i] << endl;
}
|