Code:
#include "Inventory.h"
using namespace std;
Inventory::Inventory()
{
front = NULL;
rear = NULL;
}
Inventory::~Inventory()
{
clear();
}
void Inventory::enqueue(string description, double PurchasePrice, double SalePrice)
{
if (isEmpty())
{
front = new QueueNode(description, PurchasePrice, SalePrice);
rear = front;
}
else
{
rear->next = new QueueNode(description, PurchasePrice, SalePrice);
rear = rear->next;
}
}
void Inventory::dequeue(string &description, double &PurchasePrice, double &SalePrice)
{
QueueNode *temp;
if (isEmpty())
{
cout << "The queue is empty.\n";
exit(1);
}
else
{
description = front->word;
PurchasePrice = front->value;
SalePrice = front->valueTwo;
temp = front;
front = front->next;
delete temp;
}
}
bool Inventory::isEmpty()
{
if (front ==NULL)
return true;
else
return false;
}
void Inventory::clear()
{
string word;
double value;
double valueTwo;
while(!isEmpty())
dequeue(word, value, valueTwo);
}
int main() {
Inventory iQueue;
string catchWord;
double catchVal;
double catchVal2;
cout << "Enqueuing 5 items...\n";
cout << "Enqueuing First Item...\n";
iQueue.enqueue("Red Skateboard", 50, 85);
cout << "Enqueuing Second Item...\n";
iQueue.enqueue("Green Skateboard", 45, 77);
cout << "Enqueuing Third Item...\n";
iQueue.enqueue("Blue Skateboard", 35, 76);
cout << "Enqueuing Fourth Item...\n";
iQueue.enqueue("Silver Skateboard", 44, 80);
cout << "Enqueuing Fifth Item...\n";
iQueue.enqueue("Gold Skateboard", 35, 70);
cout << "\nDequeueing 5 items...\n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
//Delete One from Inventory
cout << "\nDelete the Red Skateboard \n";
cout << "_____________________________________________________________ \n";
cout << "Enqueuing 4 items...\n";
cout << "Enqueuing First Item...\n";
iQueue.enqueue("Green Skateboard", 45, 77);
cout << "Enqueuing Second Item...\n";
iQueue.enqueue("Blue Skateboard", 35, 76);
cout << "Enqueuing Third Item...\n";
iQueue.enqueue("Silver Skateboard", 44, 80);
cout << "Enqueuing Fourth Item...\n";
iQueue.enqueue("Gold Skateboard", 35, 70);
cout << "\nDequeueing 4 items...\n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
//Add 2 More Items
cout << "\nAdding 2 new items \n";
cout << "_____________________________________________________________ \n";
cout << "Enqueuing First Item...\n";
iQueue.enqueue("Green Skateboard", 45, 77);
cout << "Enqueuing Second Item...\n";
iQueue.enqueue("Blue Skateboard", 35, 76);
cout << "Enqueuing Third Item...\n";
iQueue.enqueue("Silver Skateboard", 44, 80);
cout << "Enqueuing Fourth Item...\n";
iQueue.enqueue("Gold Skateboard", 35, 70);
cout << "Enqueuing Fifth Item...\n";
iQueue.enqueue("Orange Skateboard", 50, 72);
cout << "Enqueuing Sixth Item...\n";
iQueue.enqueue("Purple Skateboard", 45, 82);
cout << "\nDequeueing 6 items...\n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
iQueue.dequeue(catchWord, catchVal, catchVal2);
cout << "The current product is a " << catchWord << ", the purchase price is $" << catchVal << ", and a sale price of $" << catchVal2 << ". \n";
return 0;
}