C++ How to make this code take a class object instead of int for the vector...

90.2K

Verified Solution

Question

Programming

C++How to make this code take a class object instead of int for the vector queue and be able to enqueue and dequeue the object?#include 
#include 
#include 
using namespace std;
 
void print_queue(queue Q) //This function is used to print queue
{
  while (!Q.empty())
  {
    cout<< Q.front() << \" \";
    Q.pop();
  }
}
 
int main()
{
  int n = 10;
  vector< queue > array_queues(n); //Create vector of queues of size 10, each entry has a queue of type int
 
  array_queues[0].push(3); //Push elements into queue at 0th index of vector
  array_queues[0].push(4);
  array_queues[0].push(5);
 
  array_queues[3].push(11); //Push elements into queue at 3rd index of vector
  array_queues[3].push(1);
  array_queues[3].push(8);
 
  array_queues[6].push(31); //Push elements into queue at 6th index of vector
  array_queues[6].push(55);
  array_queues[6].push(101);
  array_queues[6].push(-221);
 
  cout<<\"\n\n\";
  for(int i = 0; i < n; i++) //For each element of vector, print its queue
  {
    cout << \"index = \" << i << \", Queue: \";
    print_queue(array_queues[i]);
    cout << endl;
  }
  array_queues[6].pop(); //Dequeuing elements from queue at 6th index of vector
 
 
  cout<<\"\n\nAfter Dequeuing from 6th index\n\";
  for(int i = 0; i < n; i++) //For each element of vector, print its queue
  {
    cout << \"index = \" << i << \", Queue: \";
    print_queue(array_queues[i]);
    cout << endl;
  }
  return 0;
}
 

Answer & Explanation Solved by verified expert
4.1 Ratings (635 Votes)
Modified C code include include    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students