Please Answer in c++! add comments if you can! they help me! include the main fi
ID: 3762921 • Letter: P
Question
Please Answer in c++! add comments if you can! they help me! include the main file as well please.
1. Create a customer class. In the customer class, it should include the name and number of items each customer is trying to buy. The information for the customers should be included in the file: https://github.com/fredcmpe126/customerlist/blob/master/customerlist.txt (Links to an external site.)
2. Create a Queue from scratch using an array or linked list (take your pick, however I think doing it using a linked list should be easier). This should be similar to the way you guys created a stack in lab 6. The queue class should include these functions http://www.cplusplus.com/reference/queue/queue/ (Links to an external site.)
The queue should take a 'Customer' as an object.
3. In the main function create 3 queues. These queues will simulate how lines work in a supermarket. Each customer after being read in should be designated to a queue. The way they are designated is going to be based on the queue with the least amount of items, that is the queue with the smallest SUM of total items in it.
For example:
Queue 1 = Alex (10 items), Ben(5 items), Chris(20 items). Total items in the queue = 35 items.
Queue 2 = Dylan(15 items), Eric(5 items). Total items in the queue = 20 items.
Queue 3 = Flynn(10 items), Gary(2 items). Total items in the queue = 12 items.
Since Queue 3 has the least amount of items that is being served, the next customer would go in Queue 3.
After all the customers are assigned, output information from each queue into a text file.
Example:
Queue 1:
Alex,10
Ben,5
Chris,20
Queue 2:
Dylan,15
Eric,5
Queue 3:
Flynn,10
Gary,2
Explanation / Answer
#ifndef H_HEADER
#define H_HEADER
#include <iostream>
#include <cassert>
using namespace std;
EmptyQueue() const;
int isFullQueue() const;
Type front() const;
Type back() const;
int queueCount();
void addQueue(Type queueElement);
void deleteQueue();
queueType(int queueSize = 100);
queueType(const queueType<Type>& otherQueue); // copy constructor
~queueType(); //destructor
private:
int maxQueueSize;
int queueFront;
int queueRear;
int count;
Type *list; //pointer to array that holds queue elements
};
template<class Type>
int queueType<Type>::queueCount()
{
count = abs(queueRear);
return count;
}
template<class Type>
void queueType<Type>::initializeQueue()
{
queueFront = maxQueueSize - 1;
queueRear = maxQueueSize - 1;
}
template<class Type>
int queueType<Type>::isEmptyQueue() const
{
return (queueFront == queueRear);
}
template<class Type>
int queueType<Type>::isFullQueue() const
{
return ((queueRear + 1) % maxQueueSize == queueFront);
}
template<class Type>
void queueType<Type>::addQueue(Type newElement)
{
if (!isFullQueue())
{
queueRear = (queueRear + 1) % maxQueueSize;
list[queueRear] = newElement;
}
else
{
cout << "Cannot add to a full queue." << endl;
}
}
template<class Type>
void queueType<Type>::deleteQueue()
{
if (!isEmptyQueue())
{
queueFront = (queueFront + 1) % maxQueueSize;
}
else
{
cout << "Cannot remove from an empty queue." << endl;
}
}
template<class Type>
Type queueType<Type>::front() const
{
assert(!isEmptyQueue());
return list[(queueFront + 1) % maxQueueSize];
}
template<class Type>
Type queueType<Type>::back() const
{
assert(!isEmptyQueue());
return list[(queueRear + 1) % maxQueueSize];
}
template<class Type>
queueType<Type>::queueType(int queueSize) //constructor
{
if (queueSize <= 0)
{
cout << "Size of the array to hold the queue must "
<< "be positive."<<endl;
cout << "Creating an array of size 100." << endl;
maxQueueSize = 100;
}
else
maxQueueSize = queueSize; //set maxQueueSize to queueSize
queueFront = maxQueueSize - 1; //initialize queueFront
queueRear = maxQueueSize - 1; //initiaize queueRear
list = new Type[maxQueueSize]; //create the array to
//hold queue elements
}
template<class Type>
queueType<Type>::~queueType() //destructor
{
delete [] list;
}
template<class Type>
const queueType<Type>& queueType<Type>::operator=(const queueType<Type>& otherQueue)
{
int j;
if (this != &otherQueue) //avoid self-copy
{
maxQueueSize = otherQueue.maxQueueSize;
queueFront = otherQueue.queueFront;
queueRear = otherQueue.queueRear;
delete [] list;
list = new Type[maxQueueSize];
if (queueFront != queueRear) //if other queue is not empty
for (j = (queueFront + 1) % maxQueueSize; j <= queueRear;
j = (j + 1) % maxQueueSize) //copy other queue in this queue
list[j] = otherQueue.list[j];
} //end if
return *this;
}
template<class Type>
queueType<Type>::queueType(const queueType<Type>& otherQueue)
{
maxQueueSize = otherQueue.maxQueueSize;
queueFront = otherQueue.queueFront;
queueRear = otherQueue.queueRear;
list = new Type[maxQueueSize];
if (queueFront != queueRear) //if other queue is not empty
for (int j = (queueFront + 1) % maxQueueSize; j <= queueRear;
j = (j + 1) % maxQueueSize) //copy other queue in this queue
list[j] = otherQueue.list[j];
}