Dynamic Queue

This is a discussion on Dynamic Queue within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I am working on creating a dynamic queue and I am having some problems. I got my code ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    20

    Dynamic Queue

    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!

    Code:
    #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";
    }
    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;
    
    	cout << "Enqueuing 5 items...\n";
    	
    	
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    20
    This is what I have so far, am I completely wrong??
    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 << "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;
    }

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    20
    Never mind guys I got my code to work!

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Fragmentation with Dynamic FIFO Queue
    By fguy817817 in forum Linux Programming
    Replies: 17
    Last Post: 10-31-2009, 04:17 AM
  2. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  3. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 02:55 AM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 09:09 PM
  5. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21