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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream inFile;
ofstream outFile;
string firstName, lastName, employeeAdd, salary, employeeID, employeeSearch, line;
int choice;
char newEmployeeChoice;
char inFileName[100], inFileLast[100], inFileAdd[200], inFileSal[100], inFileID[50];
outFile.open("employee.txt", ios::app);
cout << "Please enter 1: To enter employee information: " << endl;
cout << "Please enter 2: To look for employee information: " << endl;
cin >> choice;
if (choice == 1){
do{
cout << "Please enter your first name please: ";
cin.clear();
cin.sync();
getline(cin, firstName);
cout << "Please enter your last name: ";
cin.clear();
cin.sync();
getline(cin, lastName);
cout << "Please enter your employee ID: ";
cin >> employeeID;
cout << "Please enter your home address: ";
cin.clear();
cin.sync();
getline(cin, employeeAdd);
cout << "Please enter in your monthly salary: ";
cin >> salary;
outFile << firstName << "," << lastName << "," << employeeID << "," << employeeAdd << "," << salary << endl;
cout << "Would you like to enter in another employee, Y for yes N for no: ";
cin >> newEmployeeChoice;
} while (newEmployeeChoice == 'Y');
}
else if (choice == 2){
outFile.close();
inFile.open("employee.txt");
cout << "Please enter in the employee ID of the employee you want to search: ";
cin >> employeeSearch;
while (!inFile.eof())
{
if (employeeSearch == employeeID){
inFile.getline(inFileName, 100, ',');
inFile.getline(inFileLast, 100, ',');
inFile.getline(inFileAdd, 200, ',');
inFile.getline(inFileSal, 100, ',');
inFile.getline(inFileID, 50, ',');
cout << inFileName << endl;
cout << inFileLast << endl;
cout << inFileAdd << endl;
cout << inFileSal << endl;
cout << inFileID << endl;
cout << firstName << " " << lastName << " " << employeeID << " " << employeeAdd << " " << salary << endl;
}
}
}
system("pause");
return 0;
}
|