1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Linked lists and Classes [C++]

Discussion in 'C++' started by thefriend, Sep 15, 2009.

  1. thefriend

    thefriend New Member

    Joined:
    Sep 15, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello, I'm new to Go Expert. Greetings all, I'm a somewhat new programmer into my second class of C++ at LSU.

    Our teacher has done a poor job explaining classes and linked lists, and all of a sudden threw a rather large program on us with little to no help.

    I've been all over the web trying to find tutorials that covered using structs with classes and linked lists but have come up with nothing.


    here is my empInfo.h file:
    Code:
     #include <iostream>
     #include <fstream>
     #include <cstdlib>
     using namespace std;
    
     #ifndef EMPINFO_H
     #define EMPINFO_H
    
      struct Node
      {
         int empID;
         char FNAME[512];
         char LNAME[512];
         char phoneNum[512];
         int empAGE;
         Node *next;
      };
    
      Node *start_ptr = NULL;
    
     class NodeList
     {
         public:
    
         Node *head;
    
         void input(ostream& out, NodeList *Node);
    
         int FillArray();
    
         int FillArray(NodeList *Node);
    
    
    
    
    
     };
    
     #endif
    
    Here is my prog2.cpp file:

    Code:
    
     #include <iostream>
     #include <fstream> 
     #include <cstdlib>
     #include "empInfo.h"
     using namespace std;
    
    
    
     int main()
     {
        NodeList *Node;
        NodeList *newGuy;
       
    //    NodeList *current;
    //  NodeList *start_ptr = NULL;
    //    current = start_ptr;
     
    
     
        newGuy = new NodeList;
    
        int empID;
        char FNAME[512];
        char LNAME[512];
        char phoneNum[512];
        int empAGE;   
    
        
       
        cout << newGuy->Node.empID;
     
     return 0;
     }   
    
     /**********************************************************************/
     /* FUNCTION NAME: FillArray                                           */
     /* FUNCTION PURPOSE: Fills the Array.                                 */
     /*                                                                    */
     /* Input Parameters:                                                  */
     /* 1. ifstream - Provides the data from source file.                  */
     /* 2. rope[MAX] - Provides the array that needs to be filled.         */
     /* 3. ctArray - Provides the correct max count.                       */
     /* Return value: ctArray                                              */
     /**********************************************************************/
     int NodeList::FillArray(NodeList *Node)
     {
        NodeList *NewNode;       
        NodeList *temp;
    
        ifstream fin;
        ofstream fout;
    
         
    
        fin.open("empdb.data");
        if(fin.fail())
        {
           cout << "Error: Input File.";
           exit(1);
        }
    
            do {
            temp = new NodeList;
            fin >> Node.empID;
            fin >> Node.FNAME;
            fin >> Node.LNAME;
            fin >> Node.phoneNum;
            fin >> Node.empAGE;
     
            cout << Node->empID;
            cout << endl;
            cout << Node->FNAME;
            cout << endl;
            Node->next = NULL;
          
            } while(!fin.eof());
           
        fin.close();  
        return 0;
     }
    
     void NodeList::input(ostream& out, NodeList *Node)
     {  
        
    
       NodeList *newNode;
       
       do {  
            if (newNode == NULL)
              cout << "End of list" << endl;
            else
              {
                 cout << "Name : " << newNode->Node.empID << endl;
                 cout << endl;
                 newNode->Node.next;
              }
         }
       while (newNode != NULL);
        
     }
    
    I'm trying to create a struct for the info above. Then to store them in dynamically allocated memory. I keep having problems because I don't know the correct syntax.

    This code is currently very wrong I'm sure. I've been trying to at least get the memory to fill and see if I can get a correct output.

    Can anyone point me to some sources that would help this very specific problem?

    Thanks.
     

Share This Page