Question
Hi here is my question, I want to output like this and here is my head file / queue. cpp and main I finished head
Hi here is my question, I want to output like this
and here is my head file / queue. cpp and main
I finished head and queue.cpp but not main.
-----------------------------------------------------------------head file below
using namespace std; #include
//----- Globally setting up the aliases ----------------
typedef string el_t; // el_t is an alias for the data type // el_t is unknown to the client
const int MAX_SIZE = 50; // this is the max number of elements - need to change it to 50 for client2. // MAX_SIZE is unknown to the client //-------------------------------------------------------
class queue { private: // Data members are: el_t el[MAX_SIZE]; // an array called el. // Elements will be found between front and rear but // front may be behind rear since the queue wraps around int count; // how many elements do we have right now? int front; // where the front element of the queue is. int rear; // where the rear element of the queue is.
public: // prototypes to be used by the client // Note that no parameter variables are given
//add exception handling classes here with comments class Overflow{}; // when queue gets full class Underflow{}; // when queue gets empty
queue(); // constructor to create an object ~queue(); //destructor to destroy an object
// PURPOSE: returns true if queue is empty, otherwise false bool isEmpty();
// PURPOSE: returns true if queue is full, otherwise false bool isFull();
// PURPOSE: if full, throws an exception Overflow // if not full, enters an element at the rear // PRAMETER: provide the element to be added void add(el_t);
// PURPOSE: if empty, throws an exception Underflow // if not empty, removes the front element to give it back // PRAMETER: provide a holder for the element removed (pass by ref) void remove(el_t&);
// PURPOSE: if empty, throws an exception Underflow // if not empty, give back the front element (but does not remove it) // PARAMETER: provide a holder for the element (pass by ref) void frontElem(el_t&);
// PURPOSE: returns the current size to make it // accessible to the client caller int getSize();
// PURPOSE: display everything in the queue from front to rear // enclosed in [] // if empty, displays [ empty ] void displayAll();
// PURPOSE: if empty, throws an exception Underflow //if queue has just 1 element, does nothing //if queue has more than 1 element, moves the front one to the rear void goToBack();
};
-----------------------------------------------------------queue.cpp below
using namespace std; #include
// constructor queue::queue() { count = 0; front = 0; rear = -1; // initialize data members as in the notes }
//destructor queue::~queue() { // nothing }
// PURPOSE: returns true if queue is empty, otherwise false - checks count bool queue::isEmpty() { if (count == 0) return true; else return false;
}
// PURPOSE: returns true if queue is full, otherwise false - checks count bool queue::isFull() { if (count == MAX_SIZE ) return true; else return false; }
// PURPOSE: if full, throws an exception Overflow // if not full, enters an element at the rear
// PAREMETER: provide the element (newElem) to be added void queue::add(el_t newElem) { if (isFull()){ throw Overflow(); } else { count++; rear = (rear+1)%MAX_SIZE; el[rear]=newElem;
} }
// PURPOSE: if empty, throw Underflow // if not empty, removes the front element to give it back // PARAMETER: provide a holder (removedElem) for the element removed (pass by ref) void queue::remove(el_t& removedElem) {
if (isEmpty()){ throw Underflow(); }
else { theElem = el[front]; } }
// PURPOSE: returns the current size to make it // accessible to the client caller int queue::getSize() { return count; }
// PURPOSE: display everything in the queue horizontally // from front to rear enclosed in [ ] // if empty, displays [ empty ] void queue::displayAll() { if (isEmpty()) { cout
{ cout
} cout
// PURPOSE: if empty, throws an exception Underflow //if queue has just 1 element, does nothing //if queue has more than 1 element, moves the front one to the rear by //calling remove followed by add. void queue::goToBack() { if (isEmpty()) { throw Underflow(); } else if (count > 1) { el_t removedElem; remove(removedElem); add(removedElem); }
-----------------------------------and below is the probelm I try to fix
using namespace std; #include
//Purpose of the program: ** //Algorithm: ** int main() { queue que; // ** "A", "B", "C" in the queue
while(!que.isFull()) {
try { if(que.isEmpty()){ que.add("A"); que.add("B"); que.add("C");
} else { string removedElem; que.remove(removedElem); que.add(removedElem);
} }
catch(queue::Overflow) //** { cerr
} } if(que.isFull()){ cout // end of loop 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