Intro C++ assignment | Homework Helpers

Intro C++ assignment.

Create a Queue class that implements a queue abstraction. A queue is a FIFO list (First In First Out queue). A simple example is waiting in line, where the first person in the line is the first served. New arrivals are added to the back of the line, the next person served is (removed) from the front of the line. The Queue class needs to implement the following operations: adding to the queue at one end (the tail) removing from the queue at the other end (the head) printing all items the queue (from head to tail) erasing all items in the queue (leaving the queue empty). destructor to empty the queue before it s destroyed (to release all memory) Additions and removals always occur at the opposite ends of the queue. You should create the following methods in your Queue class to implement the above operations addItem removeItem print erase Your Queue class must implement a linked list. Linked lists are implemented using individual items which contain a pointer to the next item in the list, as well as the information to be stored. Your Queue implementation uses a companion QueueItem class to represent each element in the list. A QueueItem contains character string as the data value, a unique (among all QueueItems in a Queue) integer item identifier, and a pointer to the next QueueItem in the list. The following is the definition for the QueueItem class. class QueueItem { public: QueueItem(char *pData, int id); // ctor void setNext(QueueItem *pItem); QueueItem* getNext() const; int getId() const; const char* getData() const; private: char _data[30]; // or, use a char* if you want to dynamically alloc memory const int _itemId; // unique id for item in queue QueueItem* _pNext; // next item in queue }; The QueueItem member functions are very basic, just setting or getting data members of the class. All the linked list manipulation is done by the Queue class member functions. The Queue class member functions manipulate the linked list of QueueItem s, creating and destroying QueueItem objects as needed using the C++ new and delete operators. The Queue class member data includes a pointer to the head and and pointer to the tail of the linked list of QueueItems, and an integer item counter used to provide a unique item ID for every newly created QueueItem (incremented each time a new QueueItem is added, and passed as a parameter to the QueueItem constructor. It is never decremented). The following is a partial example of the Queue class; you will need to fill in the remaining methods. class Queue { public: Queue(); // ctor inits a new empty Queue ~Queue(); // dtor erases any remaining QueueItems void addItem(char *pData); void removeItem(); private: QueueItem *_pHead; // always points to first QueueItem in the list QueueItem *_pTail; // always points to the last QueueItem in the list int _itemCounter; // always increasing for a unique id to assign to each new QueueItem }; The Queue class member functions should not have access to the private members of QueueItem objects. They call the public member functions of QueueItem. As an example, the outline of the Queue::addItem() member function is shown below. It must add a new QueueItem at the tail of the Queue, and update the _pTail pointer to point to it. The first item placed in the Queue becomes both the head and the tail of the list.: void Queue::addItem(char *pData) { // dynamically create and init a new QueueItem object QueueItem *pItem = new QueueItem(pData, ++_itemCounter); if (0 == _pHead) // check for empty queue _pHead = _pTail = pItem; else { // link new item onto tail of list using _pTail pointer } } The removeItem() method removes the head QueueItem from the queue, and should release the memory using the C++ delete operator. It updates _pHead to point at the following item (if any) as the new head. If the list becomes empty, both _pHead and _pTail must be set to null (0). It does not change the value of _itemCounter (which is always incremented when a new item is added). If called on an empty Queue, it does nothing. The erase() method removes all the items in the queue and should release the memory. To implement, you could loop calling removeItem() until the queue is empty. The Queue destructor should ensure that all items are removed from the queue. The easiest way is to call the erase() method from the destructor. The user code (main) never see s QueueItem objects, since they are used only for implementation inside of class Queue. main() has only the Queue object to work with. For example, the following code would create a queue with three elements, and then print it out: // note you may need to change the definition of the main function to // be consistent with what your C++ compiler expects. int main() { Queue myQueue; myQueue.removeItem(); myQueue.addItem( red ); myQueue.addItem( green ); myQueue.addItem( blue ); myQueue.addItem( orange ); myQueue.print(); // print contents of queue (item ID and data) myQueue.removeItem(); } Use separate header (.h) and source (.cpp) files for this homework QueueItem.h contains the class definition for QueueItem QueueItem.cpp contains the member function implementations for QueueItem Queue.h contains the class definition for Queue. Queue.cpp contains the member function implementations for Queue main.cpp contains the main() test function To test your Queue and QueueItem class implementations, write a main() program which does the following: Create a Queue Call Remove. Should do nothing since the Queue is empty. Add 4 elements. Print out the list, both the number and data. Remove 2 elements. Add 4 elements. Print out the list, both the number and data. Remove 4 elements Print out the list, both the number and data. Erase the queue. Add 3 elements. Print out the list, both the number and data. Erase the queue. Print out the list. Print a heading when printing the queue so each of the above print calls is obvious. Use unique data values for each of the items added to the queue.

Don't use plagiarized sources. Get Your Custom Essay on
Intro C++ assignment | Homework Helpers
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Order Essay

Intro C++ assignment

Calculate your paper price
Pages (550 words)
Approximate price: -

Why Choose Us

Top quality papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional academic writers

We have hired a team of professional writers experienced in academic and business writing. Most of them are native speakers and PhD holders able to take care of any assignment you need help with.

Free revisions

If you feel that we missed something, send the order for a free revision. You will have 10 days to send the order for revision after you receive the final paper. You can either do it on your own after signing in to your personal account or by contacting our support.

On-time delivery

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & confidential

We use several checkers to make sure that all papers you receive are plagiarism-free. Our editors carefully go through all in-text citations. We also promise full confidentiality in all our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

You are welcome to choose your academic level and the type of your paper. Our academic experts will gladly help you with essays, case studies, research papers and other assignments.

Admissions

Admission help & business writing

You can be positive that we will be here 24/7 to help you get accepted to the Master’s program at the TOP-universities or help you get a well-paid position.

Reviews

Editing your paper

Our academic writers and editors will help you submit a well-structured and organized paper just on time. We will ensure that your final paper is of the highest quality and absolutely free of mistakes.

Reviews

Revising your paper

Our academic writers and editors will help you with unlimited number of revisions in case you need any customization of your academic papers