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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include <iostream>
#include <iomanip>
using namespace std;
const int x = 10;
void showMenu() //show the menu
{
cout << "========================================" << endl;
cout << right << setw(25) << "Employee Payroll" << endl;
cout << endl;
cout << "1. Add employee" << endl;
cout << "2. Update employee" << endl;
cout << "3. Retrieve employee" << endl;
cout << "4. List all" << endl;
cout << "5. Quit the program" << endl;
cout << endl;
cout << "Enter your choice:" << endl;
}
void addEmployee(int, int, double); // add employeeid, hours, and payrate.
int updateEmployee(const int [], int, int); // find employee id, display the number and ask the user to enter the hours worked and payrate, modify hours and payRate
int retrieveEmployee (const int [], int, int); // ask the user to enter the id to find an employee, no modification
void listEmployee ();
int searchList(int [], int, int); // search the employeeid when called upon in the update and retrieve employee function.
int _tmain(int argc, _TCHAR* argv[])
{
int empId[x];
int hours[x];
double payRate[x];
double wages[x];
int choice, loopchoice, position=0, value;
showMenu();
cin >> choice;
if (choice == 1)
{
for (int count = 0; count < x; count++)
{
cout << "Enter the employee #:" << endl;
cin >> empId[count];
cout << "Enter the hours worked" << endl;
cin >> hours[count];
cout << "Enter the payrate" << endl;
cin >> payRate[count];
cout << "Do you want to continue? Enter 1 for yes, 2 for return to main menu." << endl;
cin >> loopchoice;
if (loopchoice == 2)
{
showMenu();
cin >> choice;
}
}
}
else if (choice == 2)
{
for (int count = 0; count < x; count++)
{
cout << "Enter the employee # you want to find" << endl;
cin >> value;
if (position == -1)
{
cout << "You have entered the wrong number" << endl;
}
searchList(empId, 20, value);
cout << "Enter the employee #:" << endl;
cin >> empId[position];
cout << "Enter the hours worked" << endl;
cin >> hours[position];
cout << "Enter the payrate" << endl;
cin >> payRate[position];
cout << "Do you want to continue? Enter 1 for yes, 2 for return to main menu." << endl;
cin >> loopchoice;
if (loopchoice == 2)
{
showMenu();
cin >> choice;
}
}
}
else if (choice == 4)
{
for (int count = 0; count < x; count++)
{
cout << "List of employees #: " << empId[count] << endl;
cout << "List of employees hours worked: " << hours[count] << endl;
cout << "List of employees pay rate: " << payRate[count] << endl;
}
}
return 0;
}
int searchList(int empId[], int numElems, int value)
{
int index = 0; // Used as a subscript to search array
int position = -1; // To record position of search value
bool found = false; // Flag to indicate if the value was found
while (index < numElems && !found)
{
if (empId[index] == value) // If the value is found
{
found = true; // Set the flag
position = index; // Record the value's subscript
}
index++; // Go to the next element
}
return position; // Return the position, or -1
}
|