Simple C++ programming (4)

Simple C++ programming (4)

Using the following UML diagram and class description, write a class named MyQueue which implements a pointer-based Queue.

Class Attributes:

  • Node is a private nested struct. It’s members are:
    • i – stores an integer value.
    • next – stores the memory address of the next node in the queue.
  • front – The front node. Stores the memory address of the first node in the queue
  • back – The last node. Stores the memory address of the last node in the queue.
  • Constructor – initializes front and back to null.
  • Destructor – frees all memory used by the queue.
  • isEmpty – returns true if the queue is empty, false otherwise.
  • isFull – returns true if there isn’t enough memory for a new node, false otherwise.
  • enqueue – accepts an integer as it’s only argument. The value is added to the end of the queue. Returns 0 if successful, -1 otherwise. Can’t enqueue if you can’t make a new node.
  • dequeue – removes the first node from the queue, freeing the it’s memory. Returns 0 if successful, -1 otherwise. Can’t dequeue from an empty list.
  • first – stores the first value in the queue to it’s reference parameter, if the queue isn’t empty. Returns 0 if successful, -1 otherwise. Will fail if the queue is empty.
  • last – stores the last value in the queue to it’s reference parameter, if the queue isn’t empty. Returns 0 if successful, -1 otherwise. Will fail if the queue is empty.

Notes:

  • The class does not interact with the user in any way, so no cin or cout statements.
  • All accessors should be marked const.
  • struct Node is nested in the class and is private.

Hints:

  • Save yourself from writing duplicate code by having the class destructor repeatedly call the dequeue method.
  • You can use this driver (see file upload) to get you started on testing.

Submission Details:

  • Place your class in it’s own header file named MyQueue.h.
  • Submit only this file.
  • Be sure to include preprocess guards( #ifndef, #define, #endif).

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper