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
|
void modifyRecord(){
string lastName;
char payrollTypeChar;
double hoursWorkedDouble, payRateDouble;
int unionCodeInt;
cout << "Last name: ";
while( !(cin >> lastName)){
cout << "Error. please re-enter Last name: ";
cin.clear();
cin.ignore(10000,'\n');
}
const int SIZE = 100;
// Number of items in the array.
int count = 0;
// Declare Array Variables for input by user
string empLastName[SIZE];
char payrollType[SIZE];
double hoursWorked[SIZE];
double payRate[SIZE];
int unionCode[SIZE];
//call getInput(...); with pointers that point to the original variables.
getInput(empLastName, payrollType, hoursWorked, payRate, unionCode, count);
for(int i = 0 ; i < count ; i ++){
if(lastName.compare(empLastName[i]) == 0){
payrollTypeChar = payrollType[i];
hoursWorkedDouble = hoursWorked[i];
payRateDouble = payRate[i];
unionCodeInt = unionCode[i];
char choice;
//ask which fields need changes
cout << "change payroll type(Y/N)? ";
if(cin >> choice && (choice == 'y' || choice == 'Y')){
cout << "Payroll type: ";
while( !(cin >> payrollTypeChar)){
cout << "Error. please re-enter Payroll type: ";
cin.clear();
cin.ignore(10000,'\n');
}
}
cout << "change hours worked(Y/N)? ";
if(cin >> choice && (choice == 'y' || choice == 'Y')){
cout << "Hours worked: ";
while( !(cin >> hoursWorkedDouble)){
cout << "Error. please re-enter Hours worked: ";
cin.clear();
cin.ignore(10000,'\n');
}
}
cout << "change pay rate(Y/N)? ";
if(cin >> choice && (choice == 'y' || choice == 'Y')){
cout << "Pay rate: ";
while( !(cin >> payRateDouble)){
cout << "Error. please re-enter Pay rate: ";
cin.clear();
cin.ignore(10000,'\n');
}
}
cout << "change Union code(Y/N)? ";
if(cin >> choice && (choice == 'y' || choice == 'Y')){
cout << "Union code: ";
while( !(cin >> unionCodeInt)){
cout << "Error. please re-enter Union code: ";
cin.clear();
cin.ignore(10000,'\n');
}
}
payrollType[i] = payrollTypeChar;
hoursWorked[i] = hoursWorkedDouble;
payRate[i] = payRateDouble;
unionCode[i] = unionCodeInt;
//display the new record
cout << "The new record: " << endl;
cout << "Last Name: " << empLastName[i] << ", Payroll Type: " << payrollType[i] << ", hours worked: " << hoursWorked[i] << ", pay rate: " << payRate[i] << ", union code: " << unionCode[i] << endl;
//write all to file
writeFile(empLastName, payrollType, hoursWorked, payRate, unionCode, count);
//sort
BubbleSort(empLastName, payrollType, hoursWorked, payRate, unionCode, count);
//display after sorting
cout << "\n\nRecords after sorting: " << endl;
for(int i = 0 ; i < count ; i ++)
cout << "Last Name: " << empLastName[i] << ", Payroll Type: " << payrollType[i] << ", hours worked: " << hoursWorked[i] << ", pay rate: " << payRate[i] << ", union code: " << unionCode[i] << endl;
return;
}
}
cout << "No matching record" << endl;
return;
}
|