I am creating a listed database of employees from an external file..it should read in the first txt file info and create the database-
and then generate a payday with a second file that has hours
worked and sales....i am just going NUTS trying to pass the files around in this prgram. I get no errors - it just crashes and points to this same line in the <list> header:
*_S++ = _Tr::to_char_type(_C);
_CATCH_IO_(_I) }
*_S = _E(0);<-------------------------------this one
_I.width(0);
_I.setstate(_S == _X ? _St | ios_base::failbit : _St);
return (_I); }
template<class _E, class _Tr> inline
i figure something must be really wrong for this to pop up but,
i am struggling to tune it down. Can anyone possiblly look and
perhaps idenitfy and error or many?
thanks so much
Code:#include<iostream> using std::cin; using std::cout; using std::endl; using std::ios; using std::ostream; using std::istream; #include<list> #include<iomanip> using namespace std; #include <fstream> using std::ifstream; using std::ofstream; //Employee base class (struct Name, struct otherdata) with derived classes of salary, hourly and commission //___________________________________________________ //Database class //#define NAME_MODE 1 // typedef list < employee > EMPLOYEE_LIST; typedef EMPLOYEE_LIST::iterator EMPLOYEE_LISTiterator; class Employee_Database { public: Employee_Database(char* filename); ~Employee_Database(){} void Run( char* filename ); private: EMPLOYEE_LIST datalist; EMPLOYEE_LISTiterator locateEmp (EmployeeData ED); char databaseFilename[256]; char dataInputFilename[256]; void showMenu(); int getMenuSelection(); void Hire(); void Fire(); void Retire(); void PrintEmployees(); void outfileEmployees(); void LoadData(); void LoadData2(); void GetDataRecord(EmployeeData &newEmployee, istream& infile); void UserInput( EmployeeData &ED); int GetNextID(); }; //database constructor Employee_Database::Employee_Database( char* filename) { strcpy( databaseFilename, filename); strcpy( dataInputFilename, " " ); datalist.clear(); } void Employee_Database::Run (char* databaseFilename) { strcpy( dataInputFilename, " " );// LoadData(); LoadData2(); int more = 1; do { showMenu(); switch (getMenuSelection()) { case 0: more = 0; break; case 1: Hire(); PrintEmployees(); break; case 2: Fire(); PrintEmployees(); break; case 3: Retire(); PrintEmployees(); break; case 4: PrintEmployees(); break; default: cout << "Invalid selection" << endl; break; } if (more) { cout << "<enter> to continue..."; cin.ignore(); cin.get(); } } while (more); }//end run void Employee_Database::showMenu() { // system( "cls" ); cout << "Employee Database Menu\n"; cout << "\n1) Hire Employee"; cout << "\n2) Fire Employee"; cout << "\n2) Retire Employee"; cout << "\n3) Print Employees"; cout << "\n [ 0 to quit ]"; cout << endl; } int Employee_Database::getMenuSelection() { int select = 0; cout << "Enter your selection: "; cin >> select; return select; } void Employee_Database::UserInput( EmployeeData &ED) { cout << "Enter Employee Name (Last, First): "; cin >> ED.name.last; cin >> ED.name.first; cout << endl; } void Employee_Database::Hire() { EmployeeData newemployee; UserInput( newemployee ); if ( strlen(newemployee.name.first) != 0 ) { newemployee.id = GetNextID(); employee employeeObject( newemployee ); datalist.push_back( employeeObject ); } } void Employee_Database::Fire() { EmployeeData badEmployee; UserInput( badEmployee); EMPLOYEE_LISTiterator iter = locateEmp( badEmployee ); if ( iter != 0 ) { datalist.erase( iter ); } } void Employee_Database::Retire()//need a way to differentiate this from fire() { EmployeeData oldEmployee; UserInput( oldEmployee); EMPLOYEE_LISTiterator iter = locateEmp( oldEmployee ); if ( iter != 0 ) { datalist.erase( iter ); } } void Employee_Database::PrintEmployees() { EMPLOYEE_LISTiterator iter; for ( iter = datalist.begin(); iter != datalist.end(); iter++ ) { iter->print(); } } void Employee_Database::outfileEmployees() { EMPLOYEE_LISTiterator iter; for ( iter = datalist.begin(); iter != datalist.end(); iter++ ) { iter->outfile(); } } void Employee_Database::LoadData() { cout << "Opening File PRO_IN.txt\n\n"; ifstream infile( "PRO_IN.txt" ); if ( infile.fail() ) { cerr << "File could not be opened." << endl; return; } EmployeeData newEmployee; cout << "EmployeeData newEmployee created"<<endl; while (!infile.eof()) { cout << "In while Loop"<<endl; GetDataRecord (newEmployee, infile); cout << "GetDataRecord passed"<<endl; //GetDataRecord (newEmployee, infile)-this call fails employee EmployeeObject(newEmployee); datalist.push_back(EmployeeObject); } }//end LoadData void Employee_Database::LoadData2() { cout << "Opening File PDy.txt.\n\n"; ifstream infile2( "PDy.txt" ); if ( infile2.fail() ) { cerr << "File could not be opened." << endl; return; } char* first = " "; char* last = " "; EmployeeData Employee1; while (!infile2.eof()) { infile2 >> first >> last; if ((strcmp(Employee1.name.last, last)==0) && (strcmp(Employee1.name.first, first)==0)) { GetDataRecord (Employee1, infile2); } } }//end LoadData2 void Employee_Database::GetDataRecord( EmployeeData &newEmployee, istream& infile) { while (!infile.eof() ) { infile >>newEmployee.name.first >>newEmployee.name.last >>newEmployee.ssn >>newEmployee.type >>newEmployee.rate; } } EMPLOYEE_LISTiterator Employee_Database::locateEmp( EmployeeData ED ) { // Searches for exact match // Returns the location via iterator EMPLOYEE_LISTiterator iter; for (iter = datalist.begin(); iter != datalist.end(); iter++ ) { if ((iter->data.name.last == ED.name.last )&& (iter->data.name.first == ED.name.first ) ) { break; } } // (condition)? value-if-true : value-if-false; return (iter == datalist.end())? iter = 0 : iter; } int Employee_Database::GetNextID() { static id = 0; return ++id; } void main() { ofstream outfile("eDatabase.txt"); if(!outfile){ cerr << "Cannot open output file" << endl; //exit(1); } Employee_Database *E_DB = new Employee_Database( "EmpDB.txt" ); E_DB->Run( "PRO_IN.txt" ); delete E_DB; cin.get(); }//main



LinkBack URL
About LinkBacks



stream;