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
  • In Java, create a program implementing the functionalities of a standard queue in a class called Queue3503....

    In Java, create a program implementing the functionalities of a standard queue in a class called Queue3503. You will test the functionalities of the Queue3503 class from the main() method of the Main class. In a queue, first inserted items are removed first and the last items are removed at the end (imagine a line to buy tickets at a ticket counter). Do NOT change your class name from "Main". The Main class should come first in your code. Your filename should be "Main.java". The Queue3503 class will contain:...

  • Study the "Queue as linked list simple example" posted in this module. Rewrite the code to...

    Study the "Queue as linked list simple example" posted in this module. Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. LListQueue.cpp ///--------------------------------------------------------------- /// File: LListQueue.cpp /// Purpose: Implementation file for a demonstration of a queue /// implemented as an array. Data type: Character /// Programming Language: C++ ///--------------------------------------------------------------- #include "LListQueue.h" ///-------------------------------------------- /// Function: LListQueue() ///...

  • 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...

  • Write a C++ program to implement Queue ADT using singly linked structure. The program includes the...

    Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...

  • 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...

  • java Create a Queue class based on java.util.LinkedList class. Your Queue class should have an enqueue(),...

    java Create a Queue class based on java.util.LinkedList class. Your Queue class should have an enqueue(), dequeue(), peek(), and isEmpy() methods. Create a new Java Application that has the following methods: A method to randomly generate a number of elements between two given values and save them in a queue A method to print a queue (10 elements per line). The original queue should remain as is after the print A method to return the number of elements on the...

  • 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...

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