Question
C++ HW Question 1 EASY QUESTION. Add to your improved queue class with the following requirements: copy constructor, queue(const queue& q) , performs a deep-copy.
C++ HW Question 1 EASY QUESTION.
Add to your improved queue class with the following requirements:
copy constructor, queue(const queue& q), performs a deep-copy.
Include deconstructor, ~queue(), that deallocates dynamic allocated elements array.
Include static int numberOfObjects and static int getNumberofObjects to keep track the number of queue objects created and deleted (see page 386-388).
Include contains(T element) as an instance function to check whether the element is in the queue (see homework Exercise 12.7).
Include print(const char*s) as an instance functions to display the title (s), the size of the queue, the front and back index of the queue, and the stored elements in the queue.
Here is the queue class without the implementation codes:
template
class Queue
{
public:
Queue();
Queue(const Queue& q);
~Queue();
bool enQueue(const T value);
T deQueue();
bool contains(const T value) const;
bool isEmpty() const;
bool isFull() const;
int getSize() const;
static int getNumberOfObjects();
void print(const char*) const;
private:
T* elements;
int size;
int front;
int back;
int capacity;
void ensureCapacity();
static int numberOfObjects;
};
Here is the code I have so far: #include
//function to expand the array when it is full template
//destructor template
// main function int main() { // create a queue of capacity 4 queue
Once the above is done please also implement the following:
Use the following main() and implement a template printNumberOfObjects() function that displays the current number of allocated queue objects, and code the section that write a queue object to and read a queue object from the queue.dat file.
template
void printNumberOfObjects()
{
// displays the current number of queue object(s)
}
int main()
{
printNumberOfObjects
Queue
printNumberOfObjects
pQ1->print("1");
pQ1->enQueue(string("hello"));
pQ1->enQueue(string("C++"));
pQ1->enQueue(string("world"));
pQ1->print("1");
Queue
delete pQ1;
Q2.print("2");
//Write Q2 into a binary file called "queue.dat"
Queue
//Read Q3 from a binary file called "queue.dat"
Q3.print("3");
printNumberOfObjects
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