Write constructors isEmpty(), Enqueue(), First(), Last(), Display(), and Dequeue
ID: 3656595 • Letter: W
Question
Write constructors isEmpty(), Enqueue(), First(), Last(), Display(), and Dequeue() function members. Need destructor, copy constructor, and assignment operator. Write isFull() for upper limit be placed on the maximum size that the queue can have (return T/F bool). Need working code from start to finish. Due tomorrow. (class Queue uses a dynamic array but I have a mix of dynamic and static. Not good but I don't know how to make all of it work with dynamic.Please fix mine so it meets all the criteria above (i changed the variables and constructor names for this posting). I have stuff I don't need but if i delete it i can't compile. Please remove it if you know it will still run. Add notes to sections that I obviously don't understand. I especially don't know how to make it display in the main. ) typedef int Element; const int MAX_CAP= 128; class Queue { public: Queue(); bool isEmpty() const; bool isFull(); int Capacity; void Enqueue(const Element &element); void Display(ostream &o) const; Element front() const; void Dequeue(); ~Queue(); void Display(); Queue(const Queue &original); const Queue &operator=(const Queue &right); int Item[MAX_CAP]; private: int first; int last; int First; //front of queue int Last; //back of queue //Element *Array; Element Array[MAX_CAP]; }; Queue::Queue() : myFirst(0), myLast(0) {} void Queue::Enqueue(const Element &element) { int E; cout << "What do I say here?"; cin >> E; int newLast = (Last + 1) % MAX_CAP; if (newLast = First) { cout << "full"; exit(1); } else { Array[Last] = element; Last = newLast; } } void Queue::Display(ostream &o) const { for (int i = First; i != Last; i = (i + 1) % MAX_CAP) cout << Array[i]; } Element Queue::first() const { Element F; if (! empty()) return (Array[First]); else { cout << "empty"; return Array[MAX_CAP - 1]; Element junk; return junk; } return F; } void Queue::Dequeue() { int D; cout << "what do I say here?"; cin >> D; if (! empty()) First = (First + 1) % MAX_CAP; else { cout << "empty"; exit(1); } } Queue::~Queue() { delete[] Array; } Queue::Queue(const Queue &original) { Capacity = original.Capacity; First = original.First; Array = new Element[Capacity]; if (Array == 0) { cout << "full"; exit(1); } } const Queue &Queue::operator=(const Queue &right) { return *this; } bool Queue::Empty() const { if(First == Last) { return TRUE; } else { return NOT TRUE; } void Queue::Display() { int i; cout << "what do I write here?"; cin >> i; if(!this->empty()) { for(i =First; i !=Last; i = (i + 1) % MAX_CAP) { cout << item[i] << endl; } } else { cout << "???" << i << endl; } } bool Queue::isFull() { bool fullfull; if(First == (Last + 1) % MAX_CAP) { return TRUE; } else { return NOT TRUE; } return fullfull; } int main() { Queue queue; int i; int D; int E; int size; int fullfull; int F; int truth; cout << "Queue size?"; cin >> size; cout << size; How do I do this part? cout << " full,empty, display, enqueue, front, dequeue"; cout << "pick a number"; cin >> c; switch(c) { case 1: ???? full break; case 2:???? empty break; case 3:???? display break; case 4:???? enqueue break; case 5:???? dequeue break; } } return 0; }Explanation / Answer
#include #include using namespace std; const int MAX_SIZE = 100; class QueueOverFlowException { public: QueueOverFlowException() { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.