0% found this document useful (0 votes)
287 views6 pages

D Q, N Q

This C++ code defines a BBQ class that implements a queue data structure using an array. The class contains methods for enqueueing and dequeuing elements from the queue by manipulating pointers and shifting elements in the array. It also contains display and choice selection methods. The main function instantiates a BBQ object and runs a loop allowing the user to choose enqueue, dequeue, or exit options.

Uploaded by

Justin Ciagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
287 views6 pages

D Q, N Q

This C++ code defines a BBQ class that implements a queue data structure using an array. The class contains methods for enqueueing and dequeuing elements from the queue by manipulating pointers and shifting elements in the array. It also contains display and choice selection methods. The main function instantiates a BBQ object and runs a loop allowing the user to choose enqueue, dequeue, or exit options.

Uploaded by

Justin Ciagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include<iostream>

#include<string>

#define size 10

using namespace std;

class BBQ

private:

int pointer;

string x[size];

public:

BBQ()//constructor

pointer=10;

void display()

for (string a:x)

if (a=="")

cout<<"[ ]"<<endl;
}

else

cout<<"[ "<<a<<" ]"<<endl;

void enQueue(int num)

cout<<"Enqueuing "<<num<<".."<<endl;

string n=to_string(num);

if (pointer<=0)

cout<<"Queue is Full!"<<endl;

else

pointer--;

for (int j=0;j<9;j++)

x[j]=x[j+1];

}
x[9]=n;

void deQueue()

if (pointer==10)

cout<<"Dequeuing.."<<endl;

cout<<"Queue is Empty!"<<endl;

else

// x[pointer]="";

cout<<"Dequeuing "<<x[9]<<".."<<endl;

// x[pointer]="";

pointer++;

for (int i=9;i>=0;i--)

if (i==0)

x[i]="";

else
{

x[i]=x[i-1];

int input(string e)

int num;

bool r=true;

while (r==true)

cout<<"Enter "<<e<<": ";

if (!(cin>>num))

cin.clear();

cin.ignore();

else

r=false;

}
return num;

void choice()

cout<<"1 - Enqueue\n2 - Dequeue\n3 - Exit "<<endl;

};

int main()

BBQ q;//instance of class

int john,choice;

bool end=true;

while (end==true)

q.display();

q.choice();

choice=q.input("Choice");

switch (choice)

case 1:

// cout<<"Enter Number to Enqueue : ";

john=q.input("Number to Enqueue");
q.enQueue(john);

break;

case 2:

q.deQueue();

break;

case 3:

cout<<"Good Bye!";

end=false;

break;

default:

cout<<"Choice is not on the Options!"<<endl;

You might also like