Question
Create a queue derived from the UBArray used in Program One in C++ please. a) Each data element of each node will consist of a
Create a queue derived from the UBArray used in Program One in C++ please.
a) Each data element of each node will consist of a string object either from the STL (Standard Template Library) or from t he String definition in the 2336 directory.
2. Two functions must be created: a) Queue - to place a new node on the tail of the list. b) DeQueue - to remove a node from the head of the list.
3. Your test program should accept three commands to be given from the keyboard: a) Q string - where string is replaced by a string typed on the keyboard. This command will cause the typed string to be queued to the list. b) D - This command will cause the head string to be removed from the list and printed. c) X - Terminates the program Program One:
#include
using namespace std;
template
public: UBArray() { index = 0; } { elements.push_back(element); index++; } T At(int_index) { if (index == 0) { throw "ArrayEmpty!"; } else { return elements[_index - 1]; } } T Size() { return index; } { elements.erase(elements.begin() + _index); index--; cout << "Element deleted at" << index << "index successfully! "; }
int GetFirst() { return elements[0]; }
int GetNext(int_index) { if (_index >= index) throw "NoNextElement"; else return elements[index]; }
int GetPrev(int_index) { if ((_index - 2) < 0) throw "NoNextElement"; else return elements[index - 2]; }
void display() { cout << "UB Array elements: "; for (int i = 0; i < index; i++) { cout << elements[i] << " "; } cout << endl; } };
int main() { int op; int index,ele; UBArray
while (true) { cout << "Menu "; cout << "1.Add "; cout << "2.At "; cout << "3.Remove "; cout << "4.Size "; cout << "5.GetFirst "; cout << "6.GetLast "; cout << "7.GetNext "; cout << "8.GetPrev "; cout << "9.Display "; cout << "10.Exit "; cout << " Enter your option:"; cin >> op;
try { switch (op) { case 1: cout << "enter an element to add: "; cin >> ele; ubArray.add(ele); break; case 2: cout << "enter an index to get element "; cin >> index; cout << ubArray.At(index); break; case 3: cout << "enter an index to remoce element: "; cin >> index; ubArray.Remove(index); break; case 4: cout << "Size of the UB Array: " << ubArray.Size() << endl; break; case 5: cout << "First element in UB Array: " << ubArray.GetFirst() << endl; break; case 6: cout << "Last element in UB Array: " << ubArray.GetLast() << endl; break; case 7: cout << "enter an index to get previous element "; cin >> index; cout << "Next element in UB Array: " << ubArray.GetPrev(index) << endl; break; case 8: cout << "enter an index to get next element "; cin >> index; cout << "Next element in UB array: " << ubArray.GetNext(index) << endl; break; case 9: ubArray.display(); break; case 10: break; } if (op == 10) break; } catch (exception const& ex) { cerr << "Exception: " << ex.what() << endl; } } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started