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.
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:
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
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;
}