linked list

This is a discussion on linked list within the C++ Programming forums, part of the General Programming Boards category; here is my code and problen statement ,i cant compile it plz any one help to debug my code and ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    Unhappy linked list

    here is my code and problen statement ,i cant compile it plz any one help to debug my code and make it run.plz point out my mistakes.
    problem is
    Write a C++ program to implement employee directory, which will let the organization to perform the following functions:

    1) Insert the record of new employee
    2) Delete the record of an existing employee
    3) Find the record of an existing employee
    4) Display Report

    Following information of each employee will be stored

    Employee ID: an integer value to store the unique id for each employee
    Employee Name: the name of each employee.
    Employee Address: Address of each employee
    Employee Salary: a float value to store salary of each employee.


    Hint:


    Following information of each employee will be stored

    Employee ID: an integer value to store the unique id for each employee
    Employee Name: the name of each employee.
    Employee Address: Address of each employee
    Employee Salary: a float value to store salary of each employee.

    You can use the following structure to store the information of a single employee:

    Struct Employee {

    Int empID;
    Char *empName;
    Char *empAddress;
    Float empSalary;
    Employee * pNext;
    }Following is the sample interaction:

    Welcome to <company name> employee directory:



    1) Insert New employee
    2) Find employee
    3) Delete a record
    4) Display Report
    5) Exit
    Enter your choice: 1

    Enter EmpID: 1
    Enter EmpName: Ali
    Enter EmpAddress: VU, Lahore
    Enter Emp Salary: 20000
    Record successfully inserted (Press any Key to continue….)

    After the user presses any key the screen will be cleared and the menu will be displayed again.

    Welcome to <company name> employee directory:

    1) Insert New employee
    2) Find employee
    3) Delete a record
    4) Display Report
    5) Exit
    Enter your choice: 3 (Now user enters 3)
    Enter EmpID: 1
    Record successfully deleted (Press any key to continue…)
    After user presses any key the screen will be cleared and menu will be displayed again.

    Welcome to <company name> employee directory:

    1) Insert New employee
    2) Find employee
    3) Delete a record
    4) Display Report
    5) Exit
    Enter your choice: 2 (Now user enters 3)
    Enter EmployeID: 1
    Employee successfully deleted (Press any key to continue…)
    After user presses any key the screen will be cleared and menu will be displayed again

    Welcome to <company name> employee directory:

    1) Insert New employee
    2) Find employee
    3) Delete a record
    4) Display Report
    5) Exit
    Enter your choice: 4 (Now user enters 4)

    EmpID EmpName EmpAddress EmpSalary
    2 Raza VU, Lahore 20000
    3 Waseem VU, Lahore 25000
    5 Aslam VU, Lahore 20000

    Press any key to continue…
    After user presses any key the screen will be cleared again and menu will be displayed

    Welcome to <company name> employee directory:

    6) Insert New employee
    7) Find employee
    1) Delete a record
    2) Display Report
    3) Exit
    Enter your choice: 5 (Now user enters 5)
    Are you sure, you want to exit(y/n) y
    Program exited if user presses “y” and menu will be displayed again if user presses “n”


    and my code is

    Code:
    #include <iostream>
    using namespace std;
    
    struct node
      {  int empID;
    char *empName;
    char *empAddress;
    float empSalary;
    node * pNext;
    
         node *nxt;// Pointer to next node
      };
    
    node *start_ptr = NULL;
    node *current;		 // Used to move along the list
    int option = 0;
    
    void add_node_at_end()
      {  node *temp, *temp2;   // Temporary pointers
    
         // Reserve space for new node and fill it with data
         temp = new node;
         cout << "Please Enter EmpID ";
         cin >> temp->empID;
         cout << "Please Enter EmpName: ";
         cin >> temp->empName;
         cout << "Please Enter EmpAddress:  ";
         cin >> temp->empAddress;
         cout << "Please Enter Emp Salary:   ";
         cin >> temp->empSalary;
         temp->nxt = NULL;
    
         // Set up link to this node
         if (start_ptr == NULL)
           { start_ptr = temp;
    	 current = start_ptr;
           }
         else
           { temp2 = start_ptr;
             // We know this is not NULL - list not empty!
             while (temp2->nxt != NULL)
               {  temp2 = temp2->nxt;
                  // Move to next link in chain
               }
             temp2->nxt = temp;
           }
      }
    
    void display_list()
      {  node *temp;
         temp = start_ptr;
         cout << endl;
         if (temp == NULL)
           cout << "The list is empty!" << endl;
         else
           { while (temp != NULL)
    	   {  // Display details for what temp points to
                  cout << "Enter EmpName : " << temp->empName << " ";
                  cout << "Enter EmpID : " << temp->empID << " ";
    	      cout << "Enter EmpAddress: " << temp->empAddress;
    	      cout << "Enter Emp Salary: " << temp->empSalary;
    	      if (temp == current)
    		cout << " <-- Current node";
                  cout << endl;
    	      temp = temp->nxt;
    
    	   }
    	 cout << "End of list!" << endl;
           }
      }
    
    void delete_Record()
       { node *temp;
         temp = start_ptr;
         start_ptr = start_ptr->nxt;
         delete temp;
       }
    
    
    
    int main()
      {  start_ptr = NULL;
      int empID;
    char *empName;
    char *empAddress;
    float empSalary;
         do
    	{
    	  display_list();
    	  cout << endl;
    	  cout << "Please select an option : " << endl;
    	  cout << "0. Exit the program." << endl;
    	  cout << "1. Insert New employee," << endl;
    	  cout << "2. Delete a record from the list." << endl;
    	
    	  
              
              cout << endl << " >> ";
    	  cin >> option;
    
    	    
          switch (option)
       
          {
      
          case 1:empName;
    
          break;
    
          case 2 : delete_Record();
      
          break;
    
          case 3 : Display Report();
     
          break;
     
          default: cout << "Unknown option program will exit,";
           system("PAUSE");
        return EXIT_SUCCESS;
    } 
      
          }
      }
    Last edited by sny2ksa; 10-24-2009 at 06:34 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you can't compile it, then surely you are getting compile errors.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,655

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 11:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21