choices cannot works find

Discussion in 'C++' started by low1988, Sep 30, 2009.

  1. low1988

    low1988 New Member

    Joined:
    Sep 11, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    struct employeeInfo
    {
           string name;
           int id;
           string department;
           employeeInfo *next;
    };
    const int SIZE = 10;
    employeeInfo employed[SIZE] = {{"Michael Owen",1234,"Design"},{"Steven Gerrard",5678,"Production"},{"Fernando Torres",9012,"Management"}};
    class List {
     public:
      List(void) { head = NULL; } // constructor
      ~List(void); // destructor
      bool IsEmpty() { return head == NULL; }
      employeeInfo* InsertEmployee(string ,int ,string );
      void DisplayList(void);
      void numEmployee();
      int DeleteNode(int x);
      int FindNode(int y);
            
        private:
      employeeInfo* head;
    };
    List::~List(void) {
     employeeInfo* currNode = head, *nextNode = NULL;
     while (currNode != NULL) {
      nextNode = currNode->next;
      // destroy the current node
      delete currNode;
      currNode = nextNode;
     }
    }
    employeeInfo* List::InsertEmployee(string nama,int number,string affiliate) {
     int currIndex = 0;
     employeeInfo* currNode = head;
     employeeInfo* prevNode = NULL;
     while (currNode) {
      prevNode = currNode;
          currNode = currNode->next;
      currIndex++;
     }
       employeeInfo* newNode = new employeeInfo;
     newNode->name = nama;
     newNode->id=number;
     newNode->department= affiliate;
     if (currIndex == 0) {
      newNode->next = head;
      head = newNode;
        } else {
      newNode->next = prevNode->next;
      prevNode->next = newNode;
        }
     return newNode;
    }
     
     void List::DisplayList()
    {
     int num = 0;
     employeeInfo* currNode = head;
     while(currNode!=NULL)
     {
      cout << "Employee Name :"<<currNode->name <<endl;
      cout << "Employee ID   :"<<currNode->id<<endl;;
      cout << "Age           :"<<currNode->department<<endl;
      currNode = currNode->next;
      num++;
    }   
    }
    int List::DeleteNode(int x) {
     employeeInfo* prevNode = NULL;
     employeeInfo* currNode = head;
     int currIndex = 1;
     while (currNode && currNode->id != x) {
      prevNode = currNode;
      currNode = currNode->next;
      currIndex++;
     }
     if (currNode) {
      if (prevNode) {
       prevNode->next = currNode->next;
       delete currNode;
      } else {
       head = currNode->next;
       delete currNode;
      }
      return currIndex;
        }
     return 0;
    }
    void List::numEmployee()
    {
        int numa=0;
        int totald = 0;
        int totalp = 0;
        int totalm = 0;
        string name ,department;
        int id;
        employeeInfo* currNode = head;
        while(currNode!=NULL)
        {
                             
        if(currNode->department =="design")
        {
         totald++;
         }
                                
        if(currNode->department =="production")
        {
         totalp++;
         }
          if(currNode->department =="management")
        {
         totalm++;
         }
          currNode = currNode->next;
          }
          cout <<"Total employee in design department is :"<<totald<<endl;
           cout <<"Total employee in production department is :"<<totalp<<endl;
            cout <<"Total employee in management department is :"<<totalm<<endl;
            cout <<"Total employees of all department is :"<<totald + totalp + totalm<<endl;
          
          
          
          
         }
         
         int List::FindNode(int y) {
     employeeInfo* currNode = head;
     int currIndex = 1;
     while (currNode && currNode->id!= y) {
      currNode = currNode->next;
      currIndex++;
     }
     if (currNode)
     { cout << "Employee Name :"<<currNode->name <<endl;
      cout << "Employee ID   :"<<currNode->id<<endl;;
      cout << "Age           :"<<currNode->department<<endl;}
     else{
         cout <<"Employee not found"<<endl;
      return 0;
    }}
          
          
              
    
    int main()
    {
        int choice,logchc,numemploy,id,dselect;
        int select ;
        int count = 0;
        char ch;
        string Bpassword = "1234";
        string Hpassword = "5678";
        string password,name,departmentl,department,decide;
        
        List test;
        test.InsertEmployee("Michael",1213,"design");
        test.InsertEmployee("Steven",2345,"management");
        test.InsertEmployee("Fernando",3456,"design");
        test.InsertEmployee("Michelle",1213,"production");
        test.InsertEmployee("Fenelix",1213,"design");
        test.InsertEmployee("Michael",1213,"production");
        
        
        
        //cout <<"What position do you hold in the company ?"<<endl;
       // cout <<"\n";
       // cout <<"1.Board of Director"<<endl;
        //cout <<"2.Head of Department"<<endl;
        
      //  cin >> choice;
        
      //  if(choice == 1)
       // {
                 // cout <<"Please setup a password to sign in for further priviledges"<<endl;
                 // cout <<"Password :";
                  //cin >> Bpassword;
       // }
       // else if(choice == 2)
        //{         label:
                //  cout <<"Please setup a password for Head of Department to sign in for further priviledges"<<endl;
                //  cout <<"Password :";
                 // cin >> Hpassword;
      //  }
       // system("cls");
        label: 
        cout <<" 1.Log in as Board Director"<<endl;
        cout <<" 2.Log in as Head of Department"<<endl;
        
        cout <<"\nWhich priviledges do you wish to log in:"<<endl;
        cin >>logchc;
        if (logchc == 1)
        {
                   cout <<"You had choose to login as Board of Director"<<endl;
                   cout <<"Please enter your password:";
                   while(password != Bpassword){
                   cin >> password;
                   if(password != Bpassword)
                   cout <<"Incorrect password ,please enter again :";
                   }
                               system("cls");
                               cout <<"Log in successfully"<<endl;
                               test.numEmployee();
                               cout <<"How many employees do you wish to layoff :";
                               cin >> numemploy;
                               cout <<"From which department:";
                               cin >> departmentl;
                               cout <<"You had decide to sack "<<numemploy<<"people from"<<departmentl<<" department"<<endl;
                               cout <<"Information would further to Head of Department.In order to take action Head of department must be take action"<<endl;
                              
                               system("PAUSE");
                               system("cls");
                               goto label;
                               
                               
                               
                               }
                               
         if(logchc == 2)
         {
                   cout <<"You had choose to login as Head of Department"<<endl;
                   cout <<"Please enter your password";
                   cin >> password;
                   while(password != Hpassword){
                   cin >> password;
                   if(password != Hpassword)
                   cout <<"Incorrect password ,please enter again :";
                   }
                   system("cls");
                   cout <<"Log in successfully"<<endl;
                   cout <<"\n";
                   labelb:
                   cout <<"1.Employ new employee"<<endl;
                   cout <<"2.Layoff employee"<<endl;
                   cout <<"3.Find employee"<<endl;
                   cout <<"4.View all Information of employee"<<endl;
                   cout <<"5.Enter your selection :"<<endl;
                   cin >> select; 
                   if(select == 1)
                   {         while(decide == "y" || decide == "Y"){
                             cout << "Enter the employee's name :";
                             cin >> name;
                             cout <<"Enter the id number :";
                             cin >> id;
                             cout <<"Select the department :"<<endl;
                             cout <<"1.Design"<<endl;
                             cout <<"2.Production"<<endl;
                             cout <<"3.Management"<<endl;
                             while(dselect <= 0 || dselect >3){
                             cin >> dselect;
                             switch(dselect)
                             {
                                           case '1':department = "Design";
                                           break;
                                           case '2':department = "Production";
                                           break;
                                           case '3':department = "Management";
                                           break;
                                           default:cout <<"You had pick the wrong choice!Select again:";
                                                        }
                             test.InsertEmployee(name,id,department);
                             cout <<"Do you wish to add another employee ?<y/n>";
                             cin >>decide;
                             }
                             if(select == 2)
                             {
                             cout <<"The Board of Director had decide to fire "<<numemploy<<"people from"<<departmentl<<endl;
                             while(count < numemploy){
                             cout <<"Insert the employee ID you wish to layoff :";
                             cin >> id;
                             count++;
                             test.DeleteNode(id);
                             if(count<numemploy)
                             cout <<"Next employee"<<endl;
                             }
                              cout <<numemploy<<" of people had been fired."<<endl;
                              cout <<"Press enter to back to previous menu";
                              cin.get();
                              }
                              
                              if(select == 3)
                              {
                              while(test.FindNode(id)==0){
                              cout <<"Insert the employee ID you wish to find :";
                              cin >> id;
                              test.FindNode(id);}
                              cout <<"Press enter to back to previous menu";
                              cin.get();
                              
                              }          
                            
                               
                             
                             
                             cout <<"1.Head of department menu"<<endl;
                             cout <<"2.Log in menu"<<endl;
                             cout <<"Which menu to return :";
                             cin >> select;
                             if (select == 1)
                             goto labelb;
                             if(select == 2)
                             goto label;
                             
                             }
                             }
                             }
                               
                   
        
        
        
        
        
        
        
        getch(); 
        return 0;
    }
    
    The fucntion cannot works well when i choose to log in as Head Department and pick any choices from the menu.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    You'll find the code a lot easier to debug if you indent it correctly.

    What does it do wrong?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice