Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program in C++ - read all instructions please implement a shopping list that use

ID: 3702588 • Letter: P

Question

Program in C++ - read all instructions


please implement a shopping list that uses a linked list to store the information. The program should have a menu for the user to enter items into the list. It should store the item information into ist nodes and chain them together to form a linked list. For each item, please store the item number and the item name. For example: Item No Item Name Pizza Juice Bread 7 Implement a class LinkedList as prototyped below (header files don't have to be exactly the same as below, but they should support the same functionality). The main program should provide the user with the following options: . Add a new node at the beginning 2. Add a new node at the end 3. Remove the beginning node 4. Remove the end node 5. Remove a node from the list by entering an item number (If the item cannot be found, the program should display "Item Not Found".) 6. Remove a node from the list by entering an item name (If the item cannot be found, the program should display "Item Not Found".) . Print out the list 8. Quit the program Please print out the list after each operation. Make sure you use a linked list for the storage of the items. All of the operations should be done with the use of the linked list. You don't need to consider the duplication this time. You may implement the classes as follows:

Explanation / Answer

class LinkedList{

            public:

            LinkedList(){

                        *myHead = NULL;

                        *myTail = NULL;

                        mySize =0;

            }

            ~LinkedList();

            int size() const{

                        return mySize;

            }

            void addToStart(Node *n){

        if(myHead == NULL)

        {

            myHead = n;

            myTail = myHead;

        }

        else

        {

            n->next = myHead;

            myHead = n;

        }

                        mySize++;

            }

            void addToEnd(Node *n){

                        if(myHead == NULL)

        {

            myHead = n;

            myTail = myHead;

        }

        else

        {

            myTail->next = n;

                                    myTail = n;

        }

                        mySize++;

           

            }

            void printList(){

                        cout<<"List"<<endl;

                        cout<<"Item No "<<"Item Name"<<endl;               

        if (mySize == 0)

        {

            cout<<"Empty"<<endl;

            return;

        }   

        if (myHead->next == NULL)

        {

            cout<<myHead->itemNo<<" "<<myHead->itemName<<endl;

            return;

        }

        Node *ptr = myHead;

        cout<<myHead->itemNo<<" "<<myHead->itemName<<endl;

        ptr = myHead->next;

        while (ptr->next != NULL)

        {

            cout<<myHead->itemNo<<" "<<myHead->itemName<<endl;

            ptr = ptr->next;

        }

        cout<<ptr->itemNo<<" "<<ptr->itemName<<endl;

            }

           

            bool removeFromStart(){

                        if(mySize == 0)

                                    cout<<"No items in the list"<<endl;

                        else{

                                    Node *temp = myHead;

                                    myHead = myHead->next;

                                    free(temp);

                                    mySize--;

                        }         

            }

            bool removeFromEnd(){

                        if(mySize == 0)

                                    cout<<"No items in the list"<<endl;

                        else{

                                    Node *temp = myHead;

                                    Node *rm = myTail;

                                    while(temp->next != myTail)

                                                temp = temp->next;

                                    temp->next = NULL;

                                    myTail = temp;

                                    free(rm);         

                                    mySize--;

                        }

            }

            void removeNodeFromList(int no) {

                        if(mySize == 0)

                                    cout<<"No items in the list"<<endl;

                        else{

                                    Node *prev = myHead;

                                    Node *curr = myHead->next;

                                    if(myHead->itemNo == no){

                                                myHead = myHead->next;

                                                free(prev);

                                                mySize--;

                                                return;

                                    }

                                    while(curr->next != NULL){

                                                if(curr->itemNo == no){

                                                            prev->next = curr->next;

                                                            curr->next = NULL;

                                                            free(curr);

                                                            mySize--;

                                                            return;

                                                }

                                                else{

                                                            prev = curr;

                                                            curr = curr->next;

                                                }

                                    }

                                    cout<<"Item not found in the list"<<endl;

            }

            void removeNodeFromList(string nm) {

                        if(mySize == 0)

                                    cout<<"No items in the list"<<endl;

                        else{

                                    Node *prev = myHead;

                                    Node *curr = myHead->next;

                                    if(myHead->itemNo == nm){

                                                myHead = myHead->next;

                                                free(prev);

                                                mySize--;

                                                return;

                                    }

                                    while(curr->next != NULL){

                                                if(curr->itemNo == nm){

                                                            prev->next = curr->next;

                                                            curr->next = NULL;

                                                            free(curr);

                                                            mySize--;

                                                            return;

                                                }

                                                else{

                                                            prev = curr;

                                                            curr = curr->next;

                                                }

                                    }

                                    cout<<"Item not found in the list"<<endl;

            }

           

            private:

            Node *myHead;

            Node *myTail;

            int mySize;

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote