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
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
ifstream inFile; //declare ifstream as inFile and ofstream as outFile
ofstream outFile;
string name, add, no, pos, id, employeeSearch; //declare user inputs as string
int choice;
char newEmployeeChoice;
outFile.open("employee.txt", ios::app);
cout << "To Enter Employee Registration, press 1 & " << endl;
cout << "for Employee Payroll,press 2: ";
cin >> choice;
if (choice == 1){
do{
cout << "Employee ID: ";
cin >> id;
getline(cin, id);
cout << "Name: ";
getline(cin, name);
cout << "Address: ";
getline(cin, add);
cout << "Contact No.: ";
cin>>no;
getline(cin, no);
cout << "Position: ";
getline(cin, pos);
outFile << id << "\t" << name << "\t" << add << "\t" << no << "\t" << pos << endl;
cout << "\nWould you like to enter in another employee (y/n): ";
cin >> newEmployeeChoice;
} while (newEmployeeChoice == 'Y' || newEmployeeChoice == 'y');
}
else if (choice == 2){
outFile.close();
inFile.open("employee.txt");
cout << "Please Enter Employee ID: ";
cin >> employeeSearch;
while (getline(inFile, id, '\t'),
getline(inFile, name, '\t'),
getline(inFile, add, '\t'),
getline(inFile, no, '\t'),
getline(inFile, pos, '\n'))
if (employeeSearch == id){
cout << "\nEmployee ID: " << id << endl;
cout << "Name: " << name << endl;
cout << "Address: " << add << endl;
cout << "Contact No.: " << no << endl;
cout << "Position:" << pos << endl;
}
else
{
cout<<"Employee not found"<<endl;
}
inFile.close();
}
system("pause");
return 0;
}
|