Question

Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double
2.) Create a new C++ project and name it: Queue queue Create these three files in the project: : int : int -front o Queue.h H
Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double data type. 1.) Create a program that produces the following output OUTPUT: Q Quit Enter your choice: e Enter an item: 1.1 E Enqueue D Dequeue s-show queue ← showMenuO function called in main) OQuit // screen clears-.. continue enqueuing.screen clearing with each iteration Enter your choice: e Queue is full. E Enqueue D Dequeue s Show queue 0 - Quit ← showMenuolunction called in main) Enter your choice: d //-screen clears- // continue dequeuing screen clearing with each iteration Enter your choice: d Queue is empty E Enqueue D Dequeue s Show queue Q - Quit ← showMenuo function called in main() Enter your choice: Enter your choice: s 1.1 -2.23.3 -> 4.4 -5.5 NULL E Enqueue D Dequeue s - Show queueshowMenu0 function called in main0 Q Quit Enter your choice: d Queue is empty. */ Press any key to continue.*/
2.) Create a new C++ project and name it: Queue queue Create these three files in the project: : int : int -front o Queue.h Holds the class specification and-rear the class function definitions -items [SIZE]: double o main.cpp +Queue () +-Queue() | +ǐsFul10 +isEmpty)bool 3) In the Queue.h file, write a specification for a Queue class, based on this UML diagram. : bool 4.) Include the full function definitions in the Queue.h file. tenqueue (double item) void +dequeue (double &item): void +showQueue) : void 5.) In main.cpp file, declare a Queue object Name it: queue (size 5) 6.) Include a showMenu0 function in main to display a menu of choices. (see output above) The function is not part of the Queue class. 7.) The program should demonstrate the class functions, similar to the output Add and remove items from the queue to demonstrate enqueue&dequeue functions. Enter enough values to make the queue full, and in turn, remove all items to demonstrate an empty queue. 8.) Display all queue items
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//queue.h

#include<iostream>
using namespace std;

class Queue{
   private:
       double *arr;
       int front,rear,capacity;
      
   public:
       Queue(int size){
           capacity=size;
           front=-1;
           rear =-1;
           arr = new double[capacity];
          
       }
       ~Queue(){
           front=-1;
           rear=-1;
           capacity=0;
           delete(arr);
       }
       bool isEmpty(){
           return front==-1;
       }
       bool isFull(){
           return (rear+1)%capacity==front;
       }
       void makeEmpty(){
           front=-1;
           rear=-1;
       }
      
       void enqueue(double data){
           rear++;
       rear%=capacity;
       arr[rear]=data;
       if(front==-1)front=rear;
       }
      
  
       void dequeue(double &item){
           item = arr[front];
       if(front==rear)
           front=rear=-1;
       else{
       front++;
       front%=capacity;}
       }
      
       void showQueue(){
           int i = front;
          
           while(i!=rear){
               cout<<arr[i]<<" ";
               i++;
               i%=capacity;
           }
           cout<<arr[rear]<<" ";
           cout<<"\n\n";
       }
};
//main.cpp

#include "queue.h"

void showMenu(){
   cout<<"\nE- Enqueue\nD- Dequeue\nS- Show Queue\nQ- Quit\n";
}
int main(){
   Queue queue(5);
   char choice;
   double data;
  
   do{
       showMenu();
       cout<<"Enter your choice : ";
       cin>>choice;
      
       switch(choice){
           case'e':
           case'E':{
               if(queue.isFull()){
                   cout<<"Queue is full\n";
                  
               }
               else{
               cout<<"Enter an item : ";
               cin>>data;
               queue.enqueue(data);
               }
          
               break;
           }  
          
           case'd':
           case'D':{
               if(queue.isEmpty()){
                   cout<<"Queue is empty\n\n";
               }
               else{
                   queue.dequeue(data);
                   cout<<"item : "<<data<<"\n\n";
               }
                 
               break;
           }
           case's':
           case'S':{
               queue.showQueue();
               cout<<"\n";
               break;
           }
           case'q':
           case'Q':{
              
               cout<<"Thank you!\n";
               break;
           }
           default:{
               cout<<"Invalid choice\n\n";
               break;
           }
          
              
       }
      
   }while(choice!='q'||choice!='Q');
   return 0;
}

//sample output

CAUsers\IshuManish\ Documents| mainquuu.exe Enqueue -Dequeue - Show Queue - Quit nter your choicee nter an item 1.1 Enqueue -

Add a comment
Know the answer?
Add Answer to:
Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds value...
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
  • Step 4 Develop a class with only a main method in it: public class QueueDemo {...

    Step 4 Develop a class with only a main method in it: public class QueueDemo { public static void main(String[ ] args) { /*   Inside of this main method do the following: Create a reference to a QueueInterface<String> called myQueue and have it refer to a new object of the ImprovedQueue<String> class           Call the enqueue method on myQueue passing the String value of “A” Call the enqueue method on myQueue passing the String value of “B” Call the...

  • use intellij idea main java Step 4 Develop a class with only a main method in...

    use intellij idea main java Step 4 Develop a class with only a main method in it: public class QueueDemot public static void main(String[] args) { Inside of this main method do the following: Create a reference to a Queue Interface<String> called myQueue and have it refer to a new object of the ImprovedQueue<String> class Call the enqueue method on myQueue passing the String value of "A" Call the enqueue method on myQueue passing the String value of "B" Call...

  • The class pictured below is designed to implement an integer queue using two stacks. Assume the...

    The class pictured below is designed to implement an integer queue using two stacks. Assume the stack methods all work as desired (though their implementations are not shown). .(a) Trace what happens in the following situation, showing intermediate steps (values of variables, what is in the stacks, and what is in the queue at various points in the methods, not just the results of the methods). • Start with an empty queue. Enqueue 5, then 16, then 7. Dequeue twice....

  • Using the below files, Write a program that reads a document containing endnotes indicated in this...

    Using the below files, Write a program that reads a document containing endnotes indicated in this manner, collects them in a queue, and prints them on the screen. For this lab, you will create a text file called sample.txt and put the following paragraph in it. This part is the beginning. {This part is the footnote.} This part is the end. /* Queue.h contains the declaration of class Queue. Basic operations: Constructor: Constructs an empty queue empty: Checks if a...

  • lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the...

    lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the complete main() function, partial queue class header queue.h, and queue.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor enqueue() dequeue() You may elect to create the following helper functions: isFull() isEmpty() A description of these ADT operations are available in this Zybook and in the textbook's chapter 17. Example: If the input is: 3 Led Zepplin...

  • You are going to create a Queue. (alternately you can create a list and simply implement...

    You are going to create a Queue. (alternately you can create a list and simply implement enqueue and dequeue functions in the List – that will technically make it a queue). You will fill the first list with numbers consecutively numbered from 2 to n where n is entered by the user (we will call this Q1). When creating your Queue object use the correct function names for enqueue and dequeue functions. Again – sorry, cannot use an Javascript array...

  • i was able to make sense on the others but this two i need help Name:...

    i was able to make sense on the others but this two i need help Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: QueueNode<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue                            Access modifier: public Parameters:...

  • QUEUEBOX: Using an Array of initial size of five (5) for storage, start with the following...

    QUEUEBOX: Using an Array of initial size of five (5) for storage, start with the following generic class declaration for QueueBox: public class QueueBox<E> { private E[] elements = (ED))( new Object[5]); private int front_idx = 0; private int rear_idx = 0; private int count = 0; Hint: use the count variable to keep track of how many elements are in the queue (increment count when enqueing and decrement when dequeing). Makes it a lot easier to determine if the...

  • Write In C program Bart Simpson is a pharmacist and likes to handle his customers' request...

    Write In C program Bart Simpson is a pharmacist and likes to handle his customers' request as soon as possible. The customer who comes first get their prescription filled first. Write a menu-based program that helps Bart Simpson fill prescription order queue shown here: Name Angie Bertha Charlie Medication Lipitor Nexium Epogen The prescription queue is empty when the program starts. The menu should be as follows. Your choice is managed by switch statement and each choice requires a separated...

  • help finish Queue, don't think I have the right thing. # 1. After studying the Stack...

    help finish Queue, don't think I have the right thing. # 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...

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
ADVERTISEMENT