Question

CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class....

CS 373 Home Work project 11

Create a queue class by priviate inherting the unorderedArrayListType class. A queue class is a First-In-First-Out data structure. To understand a queue, think of a checkout line at a grocery store: the person at the front is served first (removed), and people are added to the line from the back end.

class queue : private unorderedArrayListType

{

public:

bool isEmpty() const; // test whether queue is empty

// Post: returns true if queue is empty, otherwise returns false

int size() const; // return size

// Post: returns the number of elements in the queue

int front() const; // returns the element at the front of the queue. This should be the "oldest" element, the same element that will be removed if deque() is called next

// Pre: the queue is not empty

// Post: returns the element at the front of the queue

int back() const; // returns the element at the back of the queue. This should be the "youngest" element, the same element that was added into the queue most recently using enque()

// Pre: the queue is not empty

// Post: returns the element at the back of the queue

void enque(int newItem); // insert one element at the back of the queue, after its current last element (the "youngest" element before this enque)

// Post: newItem added at the end of the queue, after the current last element

int deque(); // remove one element from the front of the queue. The "oldest" element should be removed

// Pre: the queue is not empty

// Post: the item at the front of the queue is removed from the queue and returned

queue(int size = 100);

// Post: queue initialized with capacity being size and contains 0 elements.

//       if no size is specified, 100 is used for the capacity

};

Answer this question:

Is it okay to remove the isEmpty() function from queue class and let users use the inherited isEmpty()? That’s what the unorderedArrayListType class does. Explain.

Overload the output operator << for the queue class so you can easily print out a queue (add function prologue, param type and pre-/post- comments). You have to overload it due to the private inheritance.

Add appropriate code into main to test your queue class (you may delete the existing code in main at this point). Be sure to test each function and print out current content of a queue object.   

You should not directly access the int* list data member of the arrayListType class in your implementation such as use list or list[someIndex]  Instead, you should call existing functions provided in the .cpp file.

You should not modify the given arrayListType / unorderedArrayListType code except for deleting the given main code and breaking the code into header + implementation (see next requirement).

click on the link below for snapshot of code

https://imgur.com/a/4enXnOm

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Are based on the following Queue class code segment class QueueFull {/* Empty exception class */};...

    Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...

  • This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and...

    This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and unorderedArrayList templates that are attached. Create a header file for your unorderedSet template and add it to the project. An implementation file will not be needed since the the new class will be a template. Override the definitions of insertAt, insertEnd, and replaceAt in the unorderedSet template definition. Implement the template member functions so that all they do is verify that the...

  • //This is the implementation file queue.cpp. //This is the implementation of the template class Queue. //The...

    //This is the implementation file queue.cpp. //This is the implementation of the template class Queue. //The interface for the template class Queue is in the header file queue.h. #include <iostream> #include <cstdlib> #include <cstddef> #include "queue.h" using std::cout; namespace QueueSavitch { //Uses cstddef: template<class T> Queue<T>::Queue( ) : front(NULL), back(NULL) { //Intentionally empty. } //Uses cstddef: template<class T> bool Queue<T>::isEmpty( ) const { return (back == NULL);//front == NULL would also work } //Uses cstddef: template<class T> void Queue<T>::add(T item)...

  • Please answer read the question first, don't just copy the answer from other websites, thank you...

    Please answer read the question first, don't just copy the answer from other websites, thank you very much. and this is a c++ problem. 17.Given the following class definitions class Deque; class DequeNode friend class Deque; private: int data; DequeNode *prev; DequeNode *next; class Deque private: DequeNode *head; int number; DequeNode *tail; public: Deque ) Deque() void push front (const int &); void push back (const int &) int front () int back ) int pop front ); int pop...

  • //Look for** to complete this program --C+ please --please add comments // using namespace std; #include...

    //Look for** to complete this program --C+ please --please add comments // using namespace std; #include <iostream> #include <stdlib.h> #include < string> #include "queue.h" //Purpose of the program: ** Algorithm: * int main() /** "A", "B", "C" in the queue //** while loop -- indefinitely { try {//** catches } //* end of loop } |/ II II II II II //File type: ** queue.cpp using namespace std; #include <iostream> #include "queue.h" // constructor queue::queue () } //destructor queue::~queue() queue::queue...

  • // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // ...

    // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations //   - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. //   - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...

  • The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function...

    The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that it is written as a value returning function, returning the required item. If the location of the item to be returned is out of range, use the assert function to terminate the program. note: please give all code in c++ below is the class and implementation(a test program would be helpful in determining how to use it): class arrayListType { public:    ...

  • Please Answer this question using the language of C++. I provide you with the picture of figure 1...

    Please Answer this question using the language of C++. I provide you with the picture of figure 18_02. Thank you. I 7/ Fig. 18.2: Stack.h 2 // Stack class template. #ifndef #de fine 3 STACK-H STACK-H 5 #include 7 template 8 class Stack ( 9 public: 10 I const T& top) 12 13 l/ return the top element of the Stack return stack.frontO; // push an element onto the Stack void push(const T& pushValue) 15 stack push front (pushValue); 17...

  • Design and implement a class Q that uses Q.java as a code base. The queue ADT...

    Design and implement a class Q that uses Q.java as a code base. The queue ADT must use class LinkedList from Oracle's Java class library and its underlying data structure (i.e. every Q object has-a (contains) class LinkedList object. class Q is not allowed to extend class LinkedList. The methods that are to be implemented are documented in Q.java. Method comment blocks are used to document the functionality of the class Q instance methods. The output of your program must...

  • (C++) (VISUAL STUDIO) Circular Queue is a linear data structure in which the operations are performed...

    (C++) (VISUAL STUDIO) Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. In a normal Queue, we can insert elements until queue becomes full. But once queue becomes full, we cannot insert the next element even if there is a space in front of queue. Efficiently implement a queue class using a circular...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT