Hey everyone. Before i start i'm writing up this code for my mothers employee database. I have attached two files. An example of how it's going to be run through a picture and the employee database which is a .txt file containing data such as first name, last name etc. I have started the code, and being new to this i came across a problem. I'm having trouble opening the employee.txt file to display like the example in the picture attached. I'm using a switch to call the function but had no luck. Atm i have the menu set up and i really just want to get the "alphabetized listing" working. I was told to also sort it alphabetically, but even if i can get the .txt to open in my program is more than enough help, i can work around it from there. Thanks.
Here's my code.
#include <iostream>
#include <string>
#include <iomanip>
#include <stdlib.h>
#include <fstream>
using namespace std;
// STRUCT
struct HRindex
{
int dob_y, dob_m, dob_d;
int start_y, start_m, start_d;
int pay_rate;
int exemptions;
string first_name, last_name, ssn;
int item_code;
};
ofstream outputFile;
bool outputFileIsEmpty = true;
const char* fileName = "employee.txt";
// FUNCTION PROTOTYPE
void menu();
void readAllOfFile ( ifstream & );
void displayRec ( HRindex & );
void searchRec ( ifstream & );
HRindex readFile ( ifstream &file );
void menu ()
{
int choice=5;
ifstream inputFile;
while (choice !=0)
{
cout <<endl;
cout <<endl;
cout <<"This program reads a data file of employee data, displays a menu of "<<endl;
cout <<"choices, and displays the report selected."<<endl;
cout <<endl;
cout <<endl;
cout <<" ------------------------------------ "<<endl;
cout <<" MENU "<<endl;
cout <<" ==================================="<<endl;
cout <<endl;
cout <<" 1. Alphabetizd Listing "<<endl;
cout <<endl;
cout <<" 2. Show the record for an employee "<<endl;
cout <<endl;
cout <<" 3. Budget for employee pay increases "<<endl;
cout <<endl;
cout <<" 4. Retirement elegibility "<<endl;
cout <<endl;
cout <<" 0. Exit "<<endl;
cout <<endl;
cout <<endl;
cout <<"Enter your choice := ";
cin >>choice;
switch (choice)
{
case 1:
// call function to open and sort employee.txt?
//readAllOfFile ( ifstream & );
break;
case 2:
break;
case 3:
cout <<endl;
cout <<endl;
cout <<"hello 2 "<<endl;
break;
case 4:
cout <<endl;
cout <<endl;
cout <<"hello 3 "<<endl;
break;
default :
// pops up for wrong user selection
system("cls");
}
}
cin.get();
}
void readAllOfFile( ifstream &file )
{
cout <<endl;
cout <<endl;
// displays the report heading
cout << "Employee "<<"SSN "<<"DOB " <<"Start Date "<<"Pay Rate "<<"Exemptions "<<endl;
cout <<endl;
cout << "====================================================================================="<<endl;
cout <<endl;
while ( !file.eof() )
{
// calls the readfile functnio under the display function
displayRec( readFile( file ) );
cout << endl;
}
return;
}
HRindex readFile ( ifstream &file )
{
HRindex newHRindex;
file >> newHRindex.first_name;
file >> newHRindex.last_name;
file >> newHRindex.ssn;
file >> newHRindex.dob_y;
file >> newHRindex.dob_m;
file >> newHRindex.dob_d;
file >> newHRindex.start_y;
file >> newHRindex.start_m;
file >> newHRindex.start_d;
file >> newHRindex.pay_rate;
file >> newHRindex.exemptions;
return newHRindex;
}
void displayRec ( HRindex &newHRindex )
{
cout <<endl;
cout <<newHRindex.first_name<<" "<<newHRindex.last_name <<" "<< newHRindex.ssn <<" " <<endl;//<<newHRindex.dob_y <<" "<<newHRindex.dob_m <<" "<<newHRindex.dob_d<<" "<<newHRindex.start_y<<" "<<newHRindex.start_m<<" "<<newHRindex.start_d<" "<<newHRindex.pay_rate<" "<<newHRindex.exemptions <<endl;
return;
}
//----------------------------------------------
// main menu
int main ()
{
// calls the menu function
menu();
cin.get();
return 0;
}