This assignment has three parts pertaining to the queue implementation. The parts of code are given in the .cpp and .h files. The places you need to fill out in the code are marked by // TODO.

The queue implementation is supposed to be array-based in this assignment.

  • In myqueue1.h, implement the member functions of the class MyQueue based on the first method using a counter variable that keeps track of the number of elements in the queue.
  • In myqueue2.h, implement the member functions of the class MyQueue based on the second method using the front and rear indexes only (i.e., without having the counter variable).
    • The number of elements in the queue must range from 0 to array size - 1 (i.e., the maximum capacity of the queue is the array size minus one).
    • Make sure that the calculation of the current queue size in CurrentSize() is correct. It should be calculated based only on the front and rear indexes since there is no counter variable that tracks the number of elements in the queue.
    • You may want to make use of CurrentSize()in IsFull() and IsEmpty().
  • In apptest.cpp, complete the implementation of the function CountStudent for the following problem:

The CS department at Texas State offers red and blue t-shirts to students, referred to by numbers 0 and 1, respectively. All students stand in a queue. Each student either prefers red or blue t-shirts.

The number of t-shirts provided by the department is equal to the number of students. The t-shirts are placed in a stack. At each step:

  • If the student at the front of the queue prefers the t-shirt on the top of the stack, they will take it and leave the queue.
  • Otherwise, they will leave it and go to the queue's end.

This continues until none of the queue students want to take the top t-shirt and are thus unable to have.

You are given two integer arrays students and tshirts, where tshirts[i] is the type of the i-th t-shirt in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j-th student in the initial queue (j = 0 is the front of the queue). Return the number of students who are unable to have the t- shirts.

Sample output for queuetest:

Testing the basic functions of your queue...
Please enter the max size/capacity of your queue: 3
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 5
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 8
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 7
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Nothing can be enqueued since the queue is full!
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
5 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
8 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
7 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
Nothing has been popped out since the queue is empty!
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: s

Another run:

Testing the basic functions of your queue...
Please enter the max size/capacity of your queue: 3
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 1
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 2
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 3
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Nothing can be enqueued since the queue is full!
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
1 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 4
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
2 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
3 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
4 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
Nothing has been popped out since the queue is empty!
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 5
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: e
Please enter an integer-type value you want to enqueue: 6
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
5 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
6 has been popped out.
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: d
Nothing has been popped out since the queue is empty!
Please enter 'e' for enqueue, 'd' for dequeue, and 's' for stop: s

Output for apptest:

Testing the CountStudent function...
Student Queue: 1 1 0 0
T-shirt Stack: 0 1 0 1
Number of students who are unable to have the t-shirts is: 0
Testing the CountStudent function...
Student Queue: 1 1 1 0 0 1
T-shirt Stack: 1 0 0 0 1 1
Number of students who are unable to have the t-shirts is: 3
Testing the CountStudent function...
Student Queue: 1 1 0 0 1 1 0
T-shirt Stack: 0 1 0 1 0 0 0
Number of students who are unable to have the t-shirts is: 2

Starter Codes

myqueue1.h

#ifndef _MYQUEUE1_H_
#define _MYQUEUE1_H_

#include < cstdlib>

using namespace std;

class MyQueue
{
public:
MyQueue(int size);
~MyQueue();
void EnQueue(int elem);
int DeQueue();
bool IsEmpty() const;
bool IsFull() const;

private:
int *elements; /* To declare a dynamically allocated array of integer elements for a queue (using C++ keyword new) */
int rear, front; /* The front and rear indexes of the queue */
int array_length; /* The length of an array that implements a queue */
int counter; /* The counter variable to keep track of the elements in the queue */
};

MyQueue::MyQueue(int size)
{
// TODO
}

MyQueue::~MyQueue()
{
// TODO
}

void MyQueue::EnQueue(int elem)
{
// TODO
}

int MyQueue::DeQueue()
{
// TODO
}

bool MyQueue::IsEmpty() const
{
// TODO
}

bool MyQueue::IsFull() const
{
// TODO
}

#endif

myqueue2.h

#ifndef _MYQUEUE2_H_
#define _MYQUEUE2_H_

using namespace std;

class MyQueue {
public:
MyQueue(int size);
~MyQueue();
void EnQueue(int elem);
int DeQueue();
int CurrentSize();
bool IsEmpty();
bool IsFull();

private:
int *elements; /* To declare a dynamically allocated array of integer elements for a queue (using C++ keyword new) */
int front, rear; /* The front and rear indexes of the queue */
int array_length; /* The length of an array that implements a queue */
/* Keep in mind that the queue will only hold up to (array_length - 1) elements */
/* In other words, array_length should be the maximum capacity of the queue plus one */
};

MyQueue::MyQueue(int size)
{
// TODO
}


MyQueue::~MyQueue()
{
// TODO
}

void MyQueue::EnQueue(int elem)
{
// TODO
}

int MyQueue::DeQueue()
{
// TODO
}

int MyQueue::CurrentSize()
{
// TODO
}

bool MyQueue::IsEmpty()
{
// TODO
}

bool MyQueue::IsFull()
{
// TODO
}

#endif

apptest.cpp

#include < iostream>
#include "myqueue1.h"
// Include one of your queue header files to use its corresponding queue implementation

using namespace std;

int CountStudent(int tshirt_stack[], int stack_size, int student_queue[], int queue_size)
{
// TODO
}

void Testing(int tshirts[], int tshirt_size, int students[], int student_size)
{
cout << "Testing the CountStudent function..." << endl;
cout << "Student Queue: ";
for (int i = 0; i < student_size; i++){
cout << students[i] << " ";
}
cout << endl;
cout << "T-shirt Stack: ";
for (int i = 0; i < tshirt_size; i++){
cout << tshirts[i] << " ";
}
cout << endl;
cout << "Number of students who are unable to have the t-shirts is: " << CountStudent(tshirts, tshirt_size, students, student_size) << endl;
}

int main()
{
/* Test Case 1 */
const int t1_student_size = 4;
int t1_students[t1_student_size] = { 1, 1, 0, 0 };
const int t1_tshirt_size = 4;
int t1_tshirts[t1_tshirt_size] = { 0, 1, 0, 1 };
Testing(t1_tshirts, t1_tshirt_size, t1_students, t1_student_size);

/* Test Case 2 */
const int t2_student_size = 6;
int t2_students[t2_student_size] = { 1, 1, 1, 0, 0, 1 };
const int t2_tshirt_size = 6;
int t2_tshirts[t2_tshirt_size] = { 1, 0, 0, 0, 1, 1 };
Testing(t2_tshirts, t2_tshirt_size, t2_students, t2_student_size);

/* Test Case 3 */
const int t3_student_size = 7;
int t3_students[t3_student_size] = { 1, 1, 0, 0, 1, 1, 0 };
const int t3_tshirt_size = 7;
int t3_tshirts[t3_tshirt_size] = { 0, 1, 0, 1, 0, 0, 0 };
Testing(t3_tshirts, t3_tshirt_size, t3_students, t3_student_size);

return 0;
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.