Thread: bug in my queue system

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    135

    bug in my queue system

    main.cpp
    Code:
    #include <iostream>
    #include <string>
    #include "Queue.h"
     
    using namespace std;
     
    void main(void)
    {
    	int index = 0;
    	bool menu = false;
        int mySize; //the amount of queue for the clinic
        int number;
        string name;
        int Id;
        cout << "Enter the queue you want for the maximum for the clinic: " ;
        cin >> mySize;
        cout << endl;
        while (mySize <= 0)
        {
            cout << "Please enter number greater than 0: " ;
            cin >> mySize;
            cout << endl;
        }
        Queue * theQueue = new Queue(mySize);
        system ("cls");
    	while (!menu)
    	{
    		cout << "Welcome to my Clinic queuing system!" << endl;
    		cout << "-Press <1> to get a queue number" << endl;
    		cout << "-Press <2> to get the first patient in the queue" << endl;
    		cout << "-Press <3> to print all in the queue" << endl;
    		cout << "-Press <4> to exit from this program" << endl;
    		cin >> number;
    		while (number <= 0 || number > 4)
    		{
    			cout << "Wrong input! Enter again: ";
    			cin >> number;
    		}
    		 
    			if (number == 1)
    			{
    				
    				system ("cls");
    				
    				cout << "Welcome to my Clinic queuing system!" << endl;
    				cout << "Enter your name: " ;
    				cin >> name;
    				cout << "Enter your ID: ";
    				cin >> Id;
    				theQueue ->addQueue( Id);
    				index++;
    				
    				
    				
    		     }
    
    			else if (number == 2)
    			{
    				theQueue->removeQueue();
    			}
    
    			else if (number == 3)
    			{
    				theQueue->RemovePrintQueueNumber();
    			}
    	}
        system ("pause");
    }
    Queue.h
    Code:
    #ifndef QUEUE_H_
    #define QUEUE_H_
     
    #include <string>
    using namespace std;
    class Queue
    {
    public:
        bool IsEmptyQueue(void) const;
        bool IsFullQueue(void) const;
        void initializeQueue(void);
        int Myfront(void) const;
        int Myback(void) const;
        void addQueue( int &);
    	//void addQueues(string);
        void removeQueue();
        Queue(int);
        ~Queue(void);
        void PrintNumber(void);
        void PrintQueueNumber(void);
    	void RemovePrintQueueNumber(void);
    private:
        int maxQueuesize;
        int count;
        int front;
        int back;
        int * list;
    	string * sentence;
    	string name;
    };
    #endif
    queue.cpp
    Code:
    #include "Queue.h"
    #include <cstdlib>
    #include <iostream>
    #include <string>
     
    using namespace std;
     
    bool Queue::IsEmptyQueue(void) const
    {
        return (count == 0);
    }
     
    bool Queue::IsFullQueue(void) const
    {
        return (count == maxQueuesize);
    }
     
    void Queue::initializeQueue(void)
    {
        front = 0;
        back = maxQueuesize - 1;
        count = 0;
    }
     
    int Queue::Myfront(void) const
    {
        if (!IsEmptyQueue())
        {
            return list[front];
        }
      
    }
     
    int Queue::Myback(void) const
    {
        if (!IsFullQueue())
        {
            return list[back];
        }
       
    }
     
     
    void Queue::addQueue( int & element)
    {
        if (!IsFullQueue())
        {
            back = (back + 1) % maxQueuesize;
            count++;
            list[back] = element;
    		cout << "Your queue number is " << back + 1 << endl;
    		
    	}
     
        else
        {
            cout << "Unable to add a full queue: " << endl;
        }
    }
     
    void Queue::removeQueue()
    {
        if (!IsEmptyQueue())
        {
    		
            count --;
            front = (front + 1) % maxQueuesize;
    		
    		cout << "Your queue number to be remove is " << front   << endl;
    		
    		
    		
    		
        }
        else
        {
    		cout << "There are no patients in the queue! " << endl;
    		system ("pause");
        }
    }
     
    Queue::Queue(int size)
    {
        if (size <= 0)
        {
            cout << "Size must be positive." << endl;
            cout << "An array of size 5 is created for you." << endl;
            maxQueuesize = 5;
        }
        else
        {
            maxQueuesize = size;
        }
     
        front = 0;
        back = maxQueuesize - 1;
        count = 0;
        list = new int[maxQueuesize];
     
    }
     
    Queue::~Queue(void)
    {
        delete[]  list;
    }
     
    void Queue::PrintNumber(void)
    {
        for (int i = 0; i < maxQueuesize; i ++)
        {
            cout << i << "\t:\t" << list[i] << endl;
        }
    }
     
    void Queue::PrintQueueNumber(void)
    {
        //cout << "Your queue number is " << back + 1 << endl;
        //cout << "Your queue number is " << back << endl;
    }
    
    void Queue::RemovePrintQueueNumber(void)
    {
    	//cout << "Your queue number to be remove is " << front << endl;
    }
    When i try to remove the list from the array, there are no problem until the last array where I want to remove, why is it that when i print
    in the removeQueue() function, it always print 0 instead of the max number itself .
    Example with 2 arrays

    To remove:
    Your queue number to be remove is << 1 << endl;
    Your queue number to be remove is << 0 << endl; //instead of 0

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    ignore both PrintQueueNumber or RemovePrintQueueNumber, assignment halfway complete

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (queue*)this)->queue::qput’ does not have class type
    By brack in forum C++ Programming
    Replies: 13
    Last Post: 11-11-2010, 03:41 PM
  2. Cannot convert system object to system string?
    By Robert_Sitter in forum Windows Programming
    Replies: 0
    Last Post: 11-18-2005, 02:44 PM
  3. c++ queue
    By krnjester in forum C++ Programming
    Replies: 1
    Last Post: 02-12-2002, 09:05 AM
  4. Queue and Priority Queue
    By Pamela in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2001, 11:09 PM