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; }
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;
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)