int check = 0; // Input validation statement.
// int final = 0; // Input validation statement.
int limit = 0;
struct EmployeeRec // Structure to define variables in the Employee Records.
{
string Name; // String data for the Name of studnet.
string SSN; // String name for the SSN # of the employee.
double zip; // Define zip of employees.
int age;
string DateOfHire;
bool compare(EmployeeRec valid) // Validate data
{
if(Name == valid.Name && SSN == valid.SSN && zip == valid.zip) // If statment to validate data
return true; // If correct, return true
return false; // If incorrect, return false.
}
};
void read_a_record(EmployeeRec employees[100], int &limit) // Void function for reading the .txt file of the employee records.
{
// Define string variables.
EmployeeRec cow;
int check = 0;
string full, // Full name of the employee
lastnm, // Last name of the employee.
firstnm, // First name of employee.
ssn, // SSN number of employee
name; // Name.
double zip; // Define zip.
ifstream file; // Pre-pare opening of file.
file.open("EmployeesIn.txt"); // Open EmployeeRecords.txt
if (!file) // Validation statement
{
cout << "Can't open input file " << endl; // Tell user that the file could not be read correctly.
exit(1); // End program.
}
for(int x = 0;x <= check; x++) // Make sure data is not displayed past amont of employees.
{
file >> firstnm >> lastnm >> ssn >> zip; // Call variables.
}
name = lastnm + ", " +firstnm;
// Take variable from struct
cow.Name = name; // Name
cow.SSN = ssn; // SSN
cow.zip = zip; // zip
file.close(); // Close file
check++; // Add 1 to check
}
void print_a_record(EmployeeRec show) // Function to display data
{
// Display data in orderly and readable fashion. Left center data.
cout
<< left << setw(15) << show.Name
<< setw(11) << show.SSN
<< setw(7) << fixed << setprecision(2) << show.zip << endl;
}
// Function to call Menu to display to user.
// Function to end program if user enters 5.
int end()
{
return 0;
}
void addsrecord (EmployeeRec employees[100], int &limit)
{
EmployeeRec apple;
string full; // Full name.
string DateOfHire; //Date of hire
int age; // Age of employee
string lname; // Last name
string fname; // First name
string ssn; // SSN
double zip; // zip
int location=limit+1;
if(location == 99)
{
cout << "Error, array has been exceded!!" << endl;
return;
}
limit ++;
cout << "Please enter the employee's last name.." << endl;
cin >> lname;
cout << "Please enter the employee's first name.." << endl;
cin >> fname;
full = lname + "," + fname;
apple.Name = full;
cout << "Please enter the employee's Id number" << endl;
cin >> ssn;
apple.SSN = ssn;
cout << "Please enter the employee's zip" << endl;
cin >> zip;
apple.zip = zip;
employees[location]= apple;
cout << "Please enter the employee's age" << endl;
cin >> age;
apple.age = age;
employees[age]= apple;
}
void disall (EmployeeRec employees[100], int limit)
{
int x; // Define variable
// Display all definition of data. Left center all data and display variables in
cout << left << setw(5) << "No." << left << setw(15) << "Name" << setw(11) << "SSN" << setw(7) << "zip" << endl;
cout << "--------------------------------------------------------------------\n";
for(x = 0; x <= limit; x++) // For statement to display 1 through 10, but is x has to be limited by number of studnets.
{
cout << x+1 << ". "; // Display 1 through 10 with a ".", with for statment parameters, will only diaplay till 7.
print_a_record(employees[x]); // Call print_a_function to display all data read from file.
}
}
void delsrecord ()
{
}
void findsrecord(EmployeeRec employees[100], int limit)
{
string input;
cout << "Enter the SSN number of the employee: " << endl;
cin >> input;
// loop to compare strings for the search
int count;
for (count=0; count <= limit; count++)
{
if(employees[count].SSN == input)
{
cout << "Employee has been found." << endl;
cout << "Name: " << employees[count].Name << endl << "zip: " << employees[count].zip << endl <<
"SSN: " << employees[count].SSN << endl;
return;
}
cout << count << limit << endl;
if (count==limit)
{
cout << "Can't find employee!" << endl;
}
else
{
continue;
}
}
}
void save (EmployeeRec employees [], int limit)
{
ofstream file;
file.open("EmployeesOut.txt");
string temper; // A convertName for employees[p].Name
for(int p =0; p <=limit; p++)
{
file << employees[p].Name<< " " << employees[p].SSN << " " << employees[p].zip << endl;
}
file.close ();
}
// Void statement to display menu to user.
void displayMenu(EmployeeRec employees [100])
{
cout << "Employee Records / By Akmal Adilov " << endl;
cout << endl;
cout << "Please Choose:" << endl;
cout << "(1) Add a employee record" << endl;
cout << "(3) Find an employee" << endl;
cout << "(4) Display all information in the database" << endl;
cout << "(5) Exit Program" << endl;
int input;
cin >> input;
// Input validation.
while (input < 1 || input > 5)
{
cout << "You did not enter a correct choice !" << endl;
cin >> input;
}
// Switch statement to call function user has chosen.
switch(input)
{
case 1: addsrecord(employees,limit);
save(employees,limit);
break;
case 2: delsrecord();
break;
case 3: findsrecord(employees,limit);
break;
case 4: disall(employees, limit);
break;
case 5: end ();
break;
default: cout << "You did not enter a correct choice!!" <<endl; displayMenu(employees);
break;
}
}
int main() // Open up program
{
char loop;
EmployeeRec employees[100];
read_a_record(employees, limit);
do
{
displayMenu(employees);
cout << "To continue, Please press Y, otherwise any key to quit" << endl;
cin >> loop;
}
while(loop =='Y' || loop =='y');
{
return 0;
}
system("pause");
return 0;
}
Employee Records / By Akmal Adilov
Please Choose:
(1) Add a employee record
(3) Find an employee
(4) Display all information in the database
(5) Exit Program
5
To continue, Please press Y, otherwise any key to quit
y
Employee Records / By Akmal Adilov
Please Choose:
(1) Add a employee record
(3) Find an employee
(4) Display all information in the database
(5) Exit Program
5
To continue, Please press Y, otherwise any key to quit
n
Looks fine to me. The console is supposed to close down when finished, when you don't run it manually from a console.
If you're relying on system("pause"); to keep it open, that code is never run because the