#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <stdio.h>
#include <iomanip>
#include <ctime>
using namespace std;
void mainMenu();
void readRecords();
void saveRecords();
void displayRecords();
int choice;
int takingPass(string);
int i;
int pass1;
char ch[13];
void wrong();
int ID[100];
string fname[100];
string lname[100]={string()};
char middlei[100]={char()};
string state[100]={string()};
int zip[100]={};
double hrWork[100]={};
double ratePhour[100]={};
void header()
{
cout << "Employee Records System (ERS)\n";
cout << "Long Beach City College\n";
cout << "4901 E. Carson Street\n";
cout << "Long Beach, CA 90808\n";
}
void IDcode()
{
string user;
cout << setw(10) << "\t\t ****************************************\n";
cout << setw(10) << "\t\t *Please Log-in before using application*\n";
cout << setw(10) << "\t\t ****************************************\n";
cout << "Please Enter Your User Name. "; // asking for user name
cin >> user;
cout << "Please Enter Your User ID Code. "; // asking for password
for (i=0; i<13; i++) //user can input max 13 character
{
ch[i] = getch(); // take in passwore
cout << "*"; //display * when password is input
if (ch[i]==13) //when 13 keys are enter
{
takingPass(user); // go to function takingPass
}
}
}
int takingPass(string name)
{
time_t currentTime;
time(¤tTime);
ofstream out;
out.open("c:\\UserLog.txt", ios::app); // file user login
ch[i] = 0;
pass1 = stricmp(ch,"lbcc"); //compare with name "lbcc" not sure what stricmp does(my cousin told me to use it)
if (pass1 == 0) // case insensitive
{
cout <<"\nID CODE CONFIRM \n";
out << name << " " << asctime(localtime(¤tTime))<< endl; // out put user login time and date
system("cls");
out.close();
mainMenu();
}
else
{
wrong(); // go wrong to display message to start over
}
return 0;
}
void wrong() //if password is not correct
{
cin.clear(); // clear cin
cout <<"\nUNKNOWN ID CODE\n";
cout<< endl;
system("cls"); // clear screen
IDcode();
}
int main()
{
IDcode(); // get password when program runs
}
void mainMenu() // Menu after correct password is enter
{
header();
cout << " Main Menu\n";
cout << "============\n";
cout << "1. Read Employee Records\n";
cout << "2. Save Processed Records - Files\n";
cout << "3. Display Records\n";
cout << "4. Search Records\n";
cout << "5. Sort Records \n";
cout << "6. Exit\n";
cin >> choice;
if (choice == 1) // go to readRecords
{
readRecords();
}
else if (choice == 2) // go to saveRecords
{
saveRecords();
}
else if (choice == 3) // go to displayRecords
{
displayRecords();
}
/*else if (choice == 4) // go to searchRecords
{
searchRecords();
}
else if (choice == 5) // go to sortRecords
{
sortRecords();
}*/
else if (choice == 6) // exit when 6 is enter
{
system("cls");
cout << "Logged Out"<<endl;
cout << "Press any key to close screen" <<endl;
exit(1);
}
else // when other than 1-6 is enter
{
cout << "Invalid choice";
system("cls");
mainMenu();
}
}
void readRecords()
{
ifstream inFile;
ofstream outFile;
inFile.open("c:\\FinalData.txt");
outFile.open("c:\\outData.txt");
for (int a=0; a<100; a++)
{
inFile >> ID[a] >> fname[a] >> lname[a] >> middlei[a] >> state[a] >> zip[a] >> hrWork[a] >> ratePhour[a];
cout << ID[a]<< " " << fname[a]<< endl;
}
//cout << "Records have been read" << endl;
//system("cls");
//displayRecords();
mainMenu();
}
void saveRecords()
{
/*
int ID[100]={};
string fname[100]={string()};
string lname[100]={string()};
char middlei[100]={char()};
string state[100]={string()};
int zip[100]={};
double hrWork[100]={};
double ratePhour[100]={};
*/
ifstream inFile;
ofstream outFile;
inFile.open("c:\\FinalData.txt");
outFile.open("c:\\outData.txt");
for (int a=0; a<30; a++)
{
//inFile >> ID[a] >> fname[a] >> lname[a] >> middlei[a] >> state[a] >> zip[a] >> hrWork[a] >> ratePhour[a];
outFile << ID[a]<< " " << fname[a] << " " << lname[a] << " " << middlei[a] << " " << state[a] << " " << zip[a] << " " << hrWork[a] << " " << ratePhour[a]<<endl;
}
outFile.close();
cout << "Records saved" << endl;
system("cls");
mainMenu();
}
void displayRecords()
{
/* int display;
if (display == 1)
{
findLowest();
}
else if (display == 2)
{
findHighiest();
}
else if (display == 3)
{
displayTotals();
}
/*else if (display == 4)
{
allRecords();
}
else if (display == 5)
{
DisplayMenu();
}
else if (display == 6) //
{
system("cls");
exit(1);
}
else
{
cout << "Invalid choice";
system("cls");
mainMenu();
} */
}