Hello!
I'm working on this linked list project where I'm supposed to save the employee data in a linked list and apply some operations.
and I am new with c++ so I'll show you my code and please help me with it.
my questions are:
1- whenever I enter a full name the program keeps going in an infinite loop! i used getline() method and still its not working. but if I enterd just the first name it works fine.
2- I don't know how I can display or find the employee information if I used the methods I create it gives me random data.
my code:

Main:

#include<iostream>
#include<string>
#include <fstream>
#include "EmployeeList.cpp"
using namespace std;

int main(){
    string name;
    int choice, id;
    double Salary;
    EmployeeList* employee = new EmployeeList();

    cout<<"***********************************************"<<endl;
    cout<<"**********EMPLOYEE MANAGEMENT SYSTEM***********"<<endl;
    cout<<"***********************************************\n\n"<<endl;

    do{
        cout<<" 1--->Press 1 to INSERT EMPLOYMENT:"<<endl;
        cout<<" 2--->Press 2 to FIND EMPLOYMENT INFO ID:"<<endl;
        cout<<" 3--->Press 3 to DELETE EMPLOYMENT ID:"<<endl;
        cout<<" 4--->Press 4 to SEARCH HIGHEST SALARY:"<<endl;
        cout<<" 5--->Press 5 to DISPLAY ALL EMOLYMENTS:"<<endl;
        cout<<" 6--->Press 6 to REVERSE DISPLAY ALL EMPLOYMENTS:"<<endl;
        cout<<" 7--->Press 7 to EXIT:"<<endl;
        cout<<"\n Enter Your Choice: ";
        cin>>choice;

        switch(choice){
            case 1:
                cout<<endl;
                cout<<"Enter name : ";
                getline(cin,name);
                cout<<"Enter ID : ";
                cin>>id;
                cout<<"Enter Salary : ";
                cin>>Salary;
                cout<<endl;
                employee ->INSERTEMPLOYMENT(name,id,Salary);
            break;

            case 2:
                cout<<endl;
                cout<<"Enter ID : ";
                cin>>id;
                cout<<endl;
                employee->FINDEMPLOYMENTINFOID(id);
            break;

            case 3:
                cout<<endl;
                cout<<"Employee ID : ";
                cin>>id;
                cout<<endl;
                employee-> DELETEEMPLOYMENTID(id);
            break;

            case 4:
                cout<<endl;
                employee->SEARCHHIGHESTSALARY();
            break;

            case 5:
                cout<<endl;
                employee->DISPLAYALLEMPLOYMENTS();
            break;

            case 6:
                cout<<endl;
                employee->REVERSEDISPLAYALLEMPLOYMENTS(employee->getHead());
            break;

            case 7:
                exit(0);
            default:
                cout<<"Invalid choice."<<endl;
            break;
        }
    } while (true);


    return 0;
}

Employee:

#include<iostream>
#include<stdlib.h>

using namespace std;

class Employee{
    private:
        string name;
        int ID;
        double Salary;
        Employee* next;

    public:
        //Constructor
        Employee (string n, int id, double s){
            n = name;
            id = ID;
            s = Salary;
            this->next = NULL;
        }

        //Setters
        void setName(string n){
            n = name;
        }
        void setID(int id){
            id = ID;
        }
        void setSalary(double s){
            s = Salary;
        }
        void setNext(Employee* next){
            this->next = next;
        }

        //Getters
        string getName(){
            return name;
        }

        int getID(){
            return ID;
        }

        double getSalary(){
            return Salary;
        }   
        Employee* getNext(){
            return this->next;
        }
};

EmployeeList:

#include "Employee.cpp"
using namespace std;

class EmployeeList{
    private:
        Employee* head;
    public:
    //Constructor
        EmployeeList(){         
            head = NULL;
        }
    //getter
        Employee* getHead(){
            return head;
        }

    //insert method 
        void INSERTEMPLOYMENT (string name, int id, double Salary){
            Employee* newnode = new Employee(name, id, Salary);
            if(head == NULL){
                head = newnode;
            } 
            else {
                Employee* temp = head;
                while(temp->getNext() != NULL){
                    temp = temp->getNext();
                }
                temp->setNext(newnode);
            }

            cout<<"The employee record was added successfully."<<endl;
            cout<<"------------------------------------------"<<endl;
        }

        //info
        void FINDEMPLOYMENTINFOID (int id){
            Employee *temp = head;
            bool status = false;
            while(temp != NULL){
                if(temp->getID() == id){
                    status = true;
                    cout<<"Employee Name = "<<temp->getName()<<endl;
                    cout<<"Employee ID = "<<temp->getID()<<endl;
                    cout<<"Employee Salary = "<<temp->getSalary()<<endl;
                    cout<<"---------------------------------------"<<endl;
                    }
                    temp = temp->getNext();
                }

            if(status == false) {
                cout<<"Employee is not found in the list."<<endl;
                cout<<"--------------------------------------------"<<endl;
                }
            }

        //display
        void DISPLAYALLEMPLOYMENTS (){
            Employee* temp = head;
            while(temp != NULL){
                cout<<"Employee Name = "<<temp->getName()<<endl;
                cout<<"Employee ID = "<<temp->getID()<<endl;
                cout<<"Employee Salary = "<<temp->getSalary()<<endl;
                cout<<"---------------------------------------"<<endl;
                temp = temp->getNext();
                }
            }

};
        When you:
             32:               getline(cin,name);
        You don't consider spaces, resulting in the last name being bad input for the next input, id, causing the loop.
        You could just add another getline(cin, last_name); or just use: cin >> first_name >> last_name;

    Note the differences in the working linked list below.

#include<iostream>
#include<string>
#include <fstream>
#include<stdlib.h>
#include <sstream>
#include <iomanip>
using namespace std;

int list();

int main() {
    list();

    return 0;
}

#include <iostream>
using namespace std;

class Node {
public:
    string first_name;
    string last_name;
    int id;
    double Salary;
    Node* next;

    Node()
    {
        first_name = "";
        last_name = "";
        id = 0;
        Salary = 0.0;
        next = NULL;
    }

    Node(string first_name, string last_name, int id, double Salary)
    {
        this->first_name = first_name;
        this->last_name = last_name;
        this->id = id;
        this->Salary = Salary;
        this->next = NULL;
    }
};

class Linkedlist {
    Node* head;

public:

    Linkedlist() { head = NULL; }

    void insertNode(string,string, int, double);
    void printList();
    void deleteNode(int);
};

void Linkedlist::deleteNode(int nodeOffset)
{
    Node* temp1 = head, * temp2 = NULL;
    int ListLen = 0;

    if (head == NULL) {
        cout << "List empty." << endl;
        return;
    }

    while (temp1 != NULL) {
        temp1 = temp1->next;
        ListLen++;
    }

    if (ListLen < nodeOffset) {
        cout << "Index out of range"
            << endl;
        return;
    }

    temp1 = head;

    if (nodeOffset == 1) {

        head = head->next;
        delete temp1;
        return;
    }

    while (nodeOffset-- > 1) {

        temp2 = temp1;
        temp1 = temp1->next;
    }


    temp2->next = temp1->next;
    delete temp1;
}


void Linkedlist::insertNode(string first_name, string last_name, int id, double Salary)
{

    Node* newNode = new Node(first_name, last_name, id, Salary);

    if (head == NULL) {
        head = newNode;
        return;
    }

    Node* temp = head;
    while (temp->next != NULL) {

        temp = temp->next;
    }

    temp->next = newNode;
}

void Linkedlist::printList()
{
    Node* temp = head;

    if (head == NULL) {
        cout << "List empty" << endl;
        return;
    }

    while (temp != NULL) {
        cout <<setw(15) << temp->id  << setw(10) << temp->first_name << " " << temp->last_name << setw(10) << "$" << temp->Salary << std::endl;
        temp = temp->next;
    }
}


int list()
{

    Linkedlist list;

    string first_name;
    string last_name;

    int choice = 0;
    int id = 0;
    double Salary = 0.0;
    do {
        cout << "***********************************************" << endl;
        cout << "**********EMPLOYEE MANAGEMENT SYSTEM***********" << endl;
        cout << "***********************************************\n\n" << endl;
        cout << " 1--->Press 1 to INSERT EMPLOYMENT:" << endl;
        cout << " 2--->Press 2 to DISPLAY ALL EMPLOYMENTS:" << endl;
        cout << " 7--->Press 7 to EXIT:" << endl;
        cout << "\n Enter Your Choice: ";
        cin >> choice;

        switch (choice) {
        case 1:
            cout << endl;
            cout << "Enter name : ";
            cin >> first_name >> last_name;

            cout << "Enter ID : ";
            cin >> id;
            cout << "Enter Salary : ";
            cin >> Salary;
            cout << endl;

        list.insertNode(first_name, last_name, id, Salary);
            break;
        case 2:
            std::cout << "-------------------------------------------------------------------------------" << std::endl;
            std::cout << setw(15) << "ID" << setw(15) << "Employee" << setw(25) << "Salary (millions)" << std::endl;
            std::cout << "-------------------------------------------------------------------------------" << std::endl;
            list.printList();
            cout << endl;
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        case 6:
            break;
        case 7:
            exit(0);
        default:
            cout << "Invalid choice." << endl;
            break;
        }
    } while (true);
    return 0;
}

-------------------------------------------------------------------------------
             ID       Employee        Salary (millions)
-------------------------------------------------------------------------------
              1   Michael Jordan         $33.14
             23    Lebron James         $19.07
             24      Kobe Bryant         $30.45
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.