Create a class called it TwoQueues Members Variables: a- Two int queues, One and
ID: 3700930 • Letter: C
Question
Create a class called it TwoQueues Members Variables: a- Two int queues, One and Two. b-int capacity -the maximum capacity of the queues c-int countone, int counttwo to keep track of the sizes of the queues. Function members: 1-(3 pts) Create a default constructor and set capacity to 10 and fill the first queue with 8 random numbers and the second queue with 7 random numbers. Don't forget to update the countone and counttwo appropriatel 2- (1 pt) Create int getCap) to return the capacity. 3- (5 pts) Create a function void add (int i) to add element i to queue one. If queue One is full, insert it in queue Two if there is space in it too!! 4- (6 pts) Create a function void remove_add (int k) to remove k items from queue One and add them to queue Two. You need first to check if queue One has k elements in it. If it doesn't, print an error message and return. Don't make any changes to either queues. If it does, then you need to check if queue Two has space in it to add them there as long as Two is not filled. If Two gets filled, also then print a message indicating what is happening and return 5- (4 pts) Create a void Print function to print TwoQueues object. In this function, print both queues and their sizes (countone, counttwo). You need to find a way to restore the queues after printing them out since you are popping all elements out when printing them. (1 pt) In main, create a default object que of TwoQueues a- Print que. -Call remove_add (3) -trying to remove three elements. Print que d. Call remove add (11) e-Call add four times and add 4 random numbers (make them distinguishable so they are easily viewed) Print que againExplanation / Answer
#include <iostream>
#include <cstdlib>
using namespace std;
class TwoQueues
{
int one[10],two[10];
int capacity;
int countone,counttwo;
public:
TwoQueues()
{
capacity=10;
int i;
for(i=0;i<8;i++)
one[i]=rand()%101;
countone=8;
for(i=0;i<7;i++)
two[i]=rand()%101;
counttwo=7;
}
int getCap()
{
return capacity;
}
void add(int i)
{
if(capacity>countone)
{
one[countone]=i;
countone++;
}
else if (capacity>counttwo)
{
two[counttwo]=i;
counttwo++;
}
else
{
cout<<" no list empty";
}
}
void remove_add(int k)
{
int c=0,i;
if(countone<k)
{
cout<<" Cannot remove from First Queue";
return;
}
else if (capacity!=counttwo)
{
for(i=0;i<k;i++)
{
two[counttwo]=one[i];
counttwo++;
countone--;
c++;
if(capacity==counttwo)
{
cout<<" Cannot Add in more items Second queue, No space";
}
}
for(i=0;i<countone;i++)
{
one[i]=one[c];
c++;
}
}
else
{
cout<<" No space in Second queue also";
return;
}
}
void Print()
{
int i;
int save[10];
cout<<" First Queue of size " << countone <<"is";
for(i=0;i<countone;i++)
{
cout<<" "<<one[i];
}
cout<<" Second Queue of size " << counttwo <<"is";
for(i=0;i<counttwo;i++)
{
cout<<" "<<two[i];
}
}
};
int main()
{
TwoQueues que;
que.Print();
que.remove_add(3);
que.Print();
que.remove_add(11);
for(int i=0;i<4;i++)
que.add(rand()%101);
que.Print();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.