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 110 111 112 113 114 115 116
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
ifstream inFile; //declare ifstream as inFile and ofstream as outFile
ofstream outFile;
string firstName, lastName, employeeAdd, salary, employeeID, employeeSearch, employeeModify;
string newFirst, newLast, newAdd, newSalary, newEmployID;
int choice;
char newEmployeeChoice;
outFile.open("employee.txt", ios::app); //open employee.txt and append new information
cout << "Please enter 1: To enter employee information: " << endl; //ask user for what they want to choose for the employee
cout << "Please enter 2: To look for employee information: " << endl;
cout << "Please enter 3: To modify employee information: " << endl;
cin >> choice;
if (choice == 1){ //if choice is 1 user asks employee for information
do{
cout << "Please enter your employee ID: "; //user input employee id
cin >> employeeID;
cout << "Please enter your first name please: "; //user inputs first name
cin.clear();
cin.sync();
getline(cin, firstName);
cout << "Please enter your last name: "; //user inputs last name
cin.clear();
cin.sync();
getline(cin, lastName);
cout << "Please enter your home address: "; //user inputs home address
cin.clear();
cin.sync();
getline(cin, employeeAdd);
cout << "Please enter in your monthly salary: "; //user inputs monthly salary
cin >> salary;
outFile << employeeID << "," << firstName << "," << lastName << "," << employeeAdd << "," << salary << endl; //output user info in employee.txt
cout << "\nWould you like to enter in another employee: Y for yes: "; //ask user if they have another entry
cin >> newEmployeeChoice;
} while (newEmployeeChoice == 'Y' || newEmployeeChoice == 'y'); //while loop if user inputs yes they can enter in another employee
}
else if (choice == 2){ //if choice is 2 the user will have to provide employee ID to bring up information
outFile.close(); //close employee.txt as outFile
inFile.open("employee.txt"); //open employee.txt as inFile
cout << "Please enter in the employee ID of the employee you want to search: "; //ask user for employee ID
cin >> employeeSearch;
while (getline(inFile, employeeID, ','), //while loop so it can recieve all the information from text file
getline(inFile, firstName, ','),
getline(inFile, lastName, ','),
getline(inFile, employeeAdd, ','),
getline(inFile, salary, '\n'))
if (employeeSearch == employeeID){ //if statement will compare employee ID to the one in employees.txt and the one user entere, if matches then info is displayed
cout << "\nEmployee ID: " << employeeID << endl;
cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "Employee Address: " << employeeAdd << endl;
cout << "Employee Salary: $" << salary << endl;
}
inFile.close();
}
else if (choice == 3){
inFile.open("employee.txt");
cout << "Please enter the employee number of the employee you want to modify: ";
cin >> employeeSearch;
while (getline(inFile, employeeID, ','), //while loop so it can recieve all the information from text file
getline(inFile, firstName, ','),
getline(inFile, lastName, ','),
getline(inFile, employeeAdd, ','),
getline(inFile, salary, '\n'))
if (employeeSearch == employeeID){ //if statement will compare employee ID to the one in employees.txt and the one user entere, if matches then info is displayed
cout << "\nEmployee ID: " << employeeID << endl;
cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "Employee Address: " << employeeAdd << endl;
cout << "Employee Salary: $" << salary << endl << endl;
}
cout << "Which item would you like to modify: " << endl;
cout << "Enter F: for First Name." << endl;
cout << "Enter L: for Last Name." << endl;
cout << "Enter A: for Address." << endl;
cout << "Enter S: for Salary." << endl;
cin >> employeeModify;
if (employeeModify == "F")
{
cout << "What would you like to replace the first name to: ";
cin >> newFirst;
//don't know what to do next
}
system("pause");
return 0;
}
|