Please help me explain the whole program step by step such as explain all the functions, the element, the operation, all the struct functions and so on. The coding: #include #include #include #include using namespace std; struct nodeWords {     char words[100];     struct nodeWords* next; }; struct undoWords {     char unwords[100];     struct undoWords* next; }; undoWords* untop; undoWords* newundoNode; 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() //push an element into the stack {     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() //display top of stack {     if (top == NULL)     {         cout << "\nThere is no words!\n";     }     else     {         cout << "\nTHE TOP ELEMENT IS..... ";         cout << "\nYour words > " << top->words << endl;     } } void undo() //undo last pop {     char answer2;     do {         if (untop == NULL)         {             cout << "\nThere is no words to undo!\n";             return;         }         else         {             newNode = new nodeWords;             newundoNode = new undoWords;             strcpy(newNode->words, untop->unwords);             newNode->next = top;             top = newNode;             untop = untop->next;             newundoNode->next = untop;             untop = newundoNode;             cout << "\n\nUndo Operation Success!!\n";             cout << "\nYour words > " << top->words << endl;             untop = untop->next;         }         cout << "\nPress Y to go back to MAIN MENU: ";         cin >> answer2;     } while (toupper(answer2) != 'Y'); } void display() //display all record {     char answer2;     int no = 1;     int totalRecord = 0;     {         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() //remove the last element added {     char answer4;     {         current = top;         while (current != NULL)         {             pop = current;             if (top == NULL)             {                 cout << "\nThere is no words to undo!\n";                 return;             }             else(current == top);             {                 newundoNode = new undoWords;                 strcpy(newundoNode->unwords, top->words);                 untop = newundoNode;                 top = top->next;                 current = NULL;                 delete pop;                 cout << "\n\nPop Operation Success!!\n";             }             cout << "\nPress Y to go back to MAIN MENU: ";             cin >> answer4;         }     } } int main() //main menu {     int menuOption;     top = NULL; //create list     do     {         cout << "-----------------------------------------\n";         cout << "\t\tMain Menu\n";         cout << "-----------------------------------------\n";         cout << "1 - Push/Add Record \n"; //add option         cout << "2 - Peek/Stack Top \n"; //view the top of the stack         cout << "3 - Pop/Remove Record \n"; //delete the top of the stack         cout << "4 - Display\n"; //view all records         cout << "5 - Undo\n"; //undo         cout << "6 - Exit\n"; //end program         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; 5;         case 4: display();             break;         case 5: undo();             break;         case 6: cout << system("CLS") << "\n\n\t /////PROGRAM ENDED/////\n\n";             break;         default: cout << "Wrong Option. Please re-enter your Option\n";         }     } while (menuOption != 6);     return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Repost

Please help me explain the whole program step by step such as explain all the functions, the element, the operation, all the struct functions and so on.

The coding:

#include<iostream>
#include<iomanip>
#include<ctype.h>
#include<string.h>
using namespace std;

struct nodeWords
{
    char words[100];
    struct nodeWords* next;
};
struct undoWords
{
    char unwords[100];
    struct undoWords* next;
};
undoWords* untop;
undoWords* newundoNode;

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() //push an element into the stack
{
    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() //display top of stack
{
    if (top == NULL)
    {
        cout << "\nThere is no words!\n";
    }
    else
    {
        cout << "\nTHE TOP ELEMENT IS..... ";
        cout << "\nYour words > " << top->words << endl;
    }
}

void undo() //undo last pop
{
    char answer2;
    do {
        if (untop == NULL)
        {
            cout << "\nThere is no words to undo!\n";
            return;
        }
        else
        {
            newNode = new nodeWords;
            newundoNode = new undoWords;

            strcpy(newNode->words, untop->unwords);

            newNode->next = top;
            top = newNode;
            untop = untop->next;

            newundoNode->next = untop;
            untop = newundoNode;

            cout << "\n\nUndo Operation Success!!\n";
            cout << "\nYour words > " << top->words << endl;
            untop = untop->next;
        }
        cout << "\nPress Y to go back to MAIN MENU: ";
        cin >> answer2;
    } while (toupper(answer2) != 'Y');
}

void display() //display all record
{
    char answer2;
    int no = 1;
    int totalRecord = 0;
    {
        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() //remove the last element added
{
    char answer4;
    {
        current = top;


        while (current != NULL)
        {

            pop = current;

            if (top == NULL)
            {
                cout << "\nThere is no words to undo!\n";
                return;
            }
            else(current == top);
            {
                newundoNode = new undoWords;
                strcpy(newundoNode->unwords, top->words);
                untop = newundoNode;
                top = top->next;
                current = NULL;
                delete pop;
                cout << "\n\nPop Operation Success!!\n";
            }
            cout << "\nPress Y to go back to MAIN MENU: ";
            cin >> answer4;
        }
    }
}

int main() //main menu
{
    int menuOption;

    top = NULL; //create list
    do
    {
        cout << "-----------------------------------------\n";
        cout << "\t\tMain Menu\n";
        cout << "-----------------------------------------\n";
        cout << "1 - Push/Add Record \n"; //add option
        cout << "2 - Peek/Stack Top \n"; //view the top of the stack
        cout << "3 - Pop/Remove Record \n"; //delete the top of the stack
        cout << "4 - Display\n"; //view all records
        cout << "5 - Undo\n"; //undo
        cout << "6 - Exit\n"; //end program
        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; 5;

        case 4: display();
            break;

        case 5: undo();
            break;

        case 6: cout << system("CLS") << "\n\n\t /////PROGRAM ENDED/////\n\n";
            break;

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

    return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY