ok so i know im asking for homework help but ive tried everything else and still cant seem to find what i need to know..im not nessessarily just asking for the code just for help with a particular part of it....i have a struct inside a class inside another class. i have to read from a text file into a dynamically allocated linked-list. and to sum up all the compilation errors im getting are function calls not matching, function definitions not allowed, and invalid memory addresses.
my header file looks like this:
Code://************************************************************** //Description: // define class and variables and its parameters. //************************************************************** #ifndef EMPLOYEEDATA_H #define EMPLOYEEDATA_H using namespace std; //dont know why this is required but //string wouldnt //work without it struct PERSON { int EmployeeID; string EmployeeName; string EmployeePhone; int EmployeeAge; }; class EmployeeData { private: class ListNode { friend class EmployeeData; PERSON person; ListNode *next; ListNode( PERSON person1, ListNode *next1 = NULL) { person = person1; next = next1; } }; ListNode *head; //head ptr; ListNode *result; //used to return search; public: EmployeeData() { head = NULL; } //constructor; void PrintWelcome(); void FillList(PERSON person, ifstream &inFile); void InsertNode(PERSON person); void DeleteNode(PERSON person); void DisplayList(); void PrintOne(); void Update(); int LinearSearch(); ~EmployeeData(); //deconstructor; }; #endif
my initialization file looks like this:
and my main looks like this:Code://*********************************************************************** //Description: // function declarations // //Input: // 1.EmployeeData.h // 2.iostream //*********************************************************************** #include<iostream> //for cout and NULL #include<fstream> //for file stream #include"EmployeeData.h" #include<string> using namespace std; //*********************************************************************** //Function Name: FillList //Desription: // put everything in file into dynamicaly allocated linked lists //Input: // 1. class EmployeeData // 2. iostream //*********************************************************************** void EmployeeData::FillList(PERSON person, ifstream & inFile) { ListNode *newNode; ListNode *nodePtr; ListNode *previousNodePtr = NULL; inFile>>person.EmployeeID >>person.EmployeeName >>person.EmployeePhone >>person.EmployeeAge; //allocate a new node and store struct values there newNode= new ListNode; newNode.person->EmployeeID = person.EmployeeID; newNode.person->EmployeeName= person.EmployeeName; newNode.person->EmployeePhone= person.EmployeePhone; newNode.person->EmployeeAge = person.EmployeeAge; newNode->next = NULL; while(!inFile.endof) { if(!head) head = newNode; else { //position nodePtr at the head of the list nodePtr = head; while(nodePtr->next) nodePtr = nodePtr->next; nodePtr->next = newNode; } inFile>>person.EmployeeID >>person.EmployeeName >>person.EmployeePhone >>person.EmployeeAge; //allocate a new node and store struct values there newNode= new ListNode; newNode.person->EmployeeID = person.EmployeeID; newNode.person->EmployeeName= person.EmployeeName; newNode.person->EmployeePhone= person.EmployeePhone; newNode.person->EmployeeAge = person.EmployeeAge; newNode->next = NULL; }
any help would be appreciated.Code:#include<iostream> #include<string> #include<fstream> #include<iomanip> #include<cstdlib> #include"EmployeeData.cpp" using namespace std; //global variables const int MAX = 15; //prototypes void PrintWelcome(); int main() { EmployeeData data; //class PERSON person; int number; //number of nodes ifstream inFile; inFile.open("empdb.data"); if(inFile.fail()) { cout<<"\n\nError: cannot open file"<<endl<<endl; exit(1); } PrintWelcome(); FillList(person,inFile); // ProcessTrans(students,n); inFile.close(); return 0; } //********************************************************************** //Description: // print welcome message. //********************************************************************** void PrintWelcome() { cout<<"\n\nWELCOME TO THE NEUVELLE CO. EMPLOYEE DATABASE"<<endl<<endl; }