C++ language. Using the coding prepared below, add and create the Undo last pop, Display undo list and Redo Functions void functions but keep them as they are. NOTE: use the coding given, i don't want a new coding The code: #include #include #include using namespace std; struct nodeWords {     char words[100];          struct nodeWords *next; }; nodeWords* top; //these pointers are used to hold the linked list. nodeWords* current; //use for traversal nodeWords* newNode; //use to create new node for new record nodeWords* pop;  void Push() {     char answer;     do     {         newNode = new nodeWords;         cout << "\nWrite what's in your mind.." << endl;         cout << "Your words > ";         cin >> ws;         cin.getline(newNode->words, 100);                  newNode->next = top;         top = newNode;                  cout << "\nWant to write more? Press Y for yes and N for no: ";         cin >> answer;     } while (toupper(answer) == 'Y'); } void stacktop() {     if (top == NULL)     {         cout << "\nThere is no words!\n";     }     else     {         cout << "\nTHE TOP ELEMENT IS..... ";         cout << "\nYour words > " << top->words << endl;     } } void display() {     char answer2;     int no = 1;     int totalRecord = 0;     int view;     {         cout << endl << left << setw(5) << "No" << setw(50) << "Your words" << endl;         cout << "----------------------------------------------------------------------" << endl;         current = top;         while (current != NULL)         {             cout << left << setw(5) << no << setw(50) << current->words << endl;             no++;             current = current->next;             totalRecord++;         }         cout << "----------------------------------------------------------------------" << endl;         cout << "\nTotal Number of Records: " << totalRecord << endl;     }     cout << "\nPress Y to go back to MAIN MENU: ";     cin >> answer2;     }   void Pop() {         current = top;         while (current != NULL)         {                          pop = current;             if (current == top)             {                 top = top->next;                 current = NULL;                 delete pop;                 cout << "\n\nPop Operation Success!!\n";             }             else{                     top = NULL;                     current = NULL;                     current = NULL;                     delete pop;                     cout << "\n\nPop Operation Success!!\n";             }         } } int main() {     int menuOption;     top = NULL; //create list     do     {         cout << "--------------------------------------\n";         cout << "\t\tMain Menu\n";         cout << "--------------------------------------\n";         cout << "1 - Push/Add Record \n";         cout << "2 - Peek/Stack Top \n";         cout << "3 - Pop/Remove Record \n";         cout << "4 - Display\n";         cout << "5 - Undo\n";         cout << "6 - Redo\n";         cout << "7 - Exit\n";         cout << "---------------------------------------\n";         cout << "Enter your Option [1, 2, 3, 4, 5, 6, 7]: ";         cin >> menuOption;         switch (menuOption)         {         case 1: Push();             break;         case 2: stacktop();             break;         case 3: current = top;             if (current == NULL)             {                 cout << "\n\n The List is Empty!!\n\n";                 cout << "Unable to Perform the Delete Operation.\n\n";             }             else {                 Pop();             }             break;         case 4: display();             break;                   /* case 5: undo();             break;                  case 6: redo();             break; */                      case 7: cout << system("CLS") << "\n\n\t /////PROGRAM ENDED/////\n\n";             break;         default: cout << "Wrong Option. Please re-enter your Option\n";         }     } while (menuOption != 5);     return 0; }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
icon
Related questions
icon
Concept explainers
Question

C++ language. Using the coding prepared below, add and create the Undo last pop, Display undo list and Redo Functions void functions but keep them as they are.

NOTE: use the coding given, i don't want a new coding

The code:

#include<iostream>
#include<iomanip>
#include<ctype.h>

using namespace std;

struct nodeWords
{
    char words[100];
    
    struct nodeWords *next;
};

nodeWords* top; //these pointers are used to hold the linked list.
nodeWords* current; //use for traversal
nodeWords* newNode; //use to create new node for new record
nodeWords* pop; 

void Push()
{
    char answer;
    do
    {
        newNode = new nodeWords;

        cout << "\nWrite what's in your mind.." << endl;
        cout << "Your words > ";
        cin >> ws;
        cin.getline(newNode->words, 100);
        
        newNode->next = top;
        top = newNode;
        
        cout << "\nWant to write more? Press Y for yes and N for no: ";
        cin >> answer;
    } while (toupper(answer) == 'Y');
}

void stacktop()
{
    if (top == NULL)
    {
        cout << "\nThere is no words!\n";
    }
    else
    {
        cout << "\nTHE TOP ELEMENT IS..... ";
        cout << "\nYour words > " << top->words << endl;
    }
}

void display()
{
    char answer2;
    int no = 1;
    int totalRecord = 0;
    int view;
    {

        cout << endl << left << setw(5) << "No" << setw(50) << "Your words" << endl;
        cout << "----------------------------------------------------------------------" << endl;
        current = top;
        while (current != NULL)
        {
            cout << left << setw(5) << no << setw(50) << current->words << endl;
            no++;
            current = current->next;
            totalRecord++;
        }
        cout << "----------------------------------------------------------------------" << endl;
        cout << "\nTotal Number of Records: " << totalRecord << endl;

    }
    cout << "\nPress Y to go back to MAIN MENU: ";
    cin >> answer2;
    }
 
void Pop()
{
        current = top;

        while (current != NULL)
        {
            
            pop = current;

            if (current == top)
            {
                top = top->next;
                current = NULL;
                delete pop;
                cout << "\n\nPop Operation Success!!\n";
            }
            else{
                    top = NULL;
                    current = NULL;
                    current = NULL;
                    delete pop;
                    cout << "\n\nPop Operation Success!!\n";
            }
        }
}


int main()
{
    int menuOption;

    top = NULL; //create list
    do
    {
        cout << "--------------------------------------\n";
        cout << "\t\tMain Menu\n";
        cout << "--------------------------------------\n";
        cout << "1 - Push/Add Record \n";
        cout << "2 - Peek/Stack Top \n";
        cout << "3 - Pop/Remove Record \n";
        cout << "4 - Display\n";
        cout << "5 - Undo\n";
        cout << "6 - Redo\n";
        cout << "7 - Exit\n";
        cout << "---------------------------------------\n";

        cout << "Enter your Option [1, 2, 3, 4, 5, 6, 7]: ";
        cin >> menuOption;

        switch (menuOption)
        {
        case 1: Push();
            break;

        case 2: stacktop();
            break;

        case 3: current = top;
            if (current == NULL)
            {
                cout << "\n\n The List is Empty!!\n\n";
                cout << "Unable to Perform the Delete Operation.\n\n";
            }
            else {
                Pop();
            }
            break;

        case 4: display();
            break;
            
     /* case 5: undo();
            break;
        
        case 6: redo();
            break; */
            
        case 7: cout << system("CLS") << "\n\n\t /////PROGRAM ENDED/////\n\n";
            break;

        default: cout << "Wrong Option. Please re-enter your Option\n";
        }
    } while (menuOption != 5);

    return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage