Hey guys, I am working on creating a dynamic queue and I am having some problems. I got my code wrote to set up the actual code but I am unsure how to put my information in and print it. I need to enter the following information in my queue and print it.

"Red Skateboard", 50, 85
"Green Skateboard", 45, 77
"Blue Skateboard", 35, 76
"Silver Skateboard", 44, 80
"Gold Skateboard", 35, 70

Here is my code can someone please show me what I need to do!

#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;

//Inventory Class
class Inventory 
{
private:
	class QueueNode
	{
		friend class Inventory;
		string word;
		double value;
		double valueTwo;
		QueueNode *next;

		//Constructor
		QueueNode(string word1, double value1, double value2, QueueNode *next1 = NULL)
		{
			word = word1;
			value = value1;
			valueTwo = value2;
			next = next1;
		}
	};
	QueueNode *front;
	QueueNode *rear;

	string description;
	double PurchasePrice;
	double SalePrice;

public:
	Inventory();
	~Inventory();

	void enqueue(string, double, double);
	void dequeue(string &, double &, double &);
	bool isEmpty();
	void clear();
	

	void New_inventory (string a, double b, double c)
	{description = a; PurchasePrice = b; SalePrice = c;}
	
	//mutator and accessor functions
	Inventory (string, double, double);
	void setDescription(string);
	void setPurchasePrice(double);
	void setSalePrice(double);

	string getDescription();
	double getPurchasePrice();
	double getSalePrice();

	void interest_details();
};


Inventory::Inventory(string description, double PurchasePrice, double SalePrice)
{
//this pointers to current class
	this->description = description;
	this->PurchasePrice = PurchasePrice;
	this->SalePrice = SalePrice;

}

void Inventory::setDescription(string description)	{
	Inventory::description = description;
}

void Inventory::setPurchasePrice(double PurchasePrice)	{
	Inventory::PurchasePrice = PurchasePrice;
}

void Inventory::setSalePrice(double SalePrice)	{
	Inventory::SalePrice = SalePrice;
}

string Inventory::getDescription() {
	return description;
}

double Inventory::getPurchasePrice() {
	return PurchasePrice;
}

double Inventory::getSalePrice() {
	return SalePrice;

}

void Inventory::interest_details() {
	cout << "The current product it a " << description <<
		", the purchase price is " << PurchasePrice <<
		", anda sale price of " << SalePrice << ".\n";
}
#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;

	cout << "Enqueuing 5 items...\n";
	
	

	return 0;
}

Dani AI

Generated

Nice job — you tracked the problem down and got a working queue. A few concise improvements and safety checks will make the class more robust and easier to maintain.

Use const references for strings and clearer function return behavior (avoid calling exit from a library method). For example, prefer signatures like:

void enqueue(const std::string& desc, double purchase, double sale);
bool dequeue(std::string& desc, double& purchase, double& sale); // returns false if empty

Add a non-destructive printer/peek so callers can inspect the queue without removing nodes:

void printAll() const {
    auto cur = front;
    while (cur) {
        std::cout << cur->word << "  $" << cur->value << "  $" << cur->valueTwo << '\n';
        cur = cur->next;
    }
}

Watch pointer edge-cases: when you dequeue the last node you must set both front and rear to nullptr to avoid a dangling rear. Initialize members with initializer lists (Inventory() : front(nullptr), rear(nullptr) {}) and use nullptr instead of NULL if compiling with C++11 or later.

Ownership and copying: because the class manages raw pointers, follow the Rule of Three/Five — either implement a deep copy and assignment or explicitly disable copying to prevent shallow-copy bugs:

Inventory(const Inventory&) = delete;
Inventory& operator=(const Inventory&) = delete;

Other suggestions: avoid using namespace std; in headers, maintain a size counter if you need O(1) size(), and consider using std::queue/std::list or smart pointers to simplify lifetime management. Finally, format money with std::fixed << std::setprecision(2) when printing prices. These small changes will make the queue safer and easier to extend.

This is what I have so far, am I completely wrong??

#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 << "Dequeueing 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";



	

	return 0;
}

Never mind guys I got my code to work!

#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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.