Thread: Cicrcular queue help

  1. #16
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    Ai ya, is there any new ways to solve the function problem to store the name and ID for the class function without using composition.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Stop avoiding the problem and learn how to do it properly.
    This is basics of basics. If you cannot master this, then you are not a programmer and cannot hope to be.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    I am asking user to input the size of the queue(eg. 20, 30, 40) and the program would used the size from the user. Of course i need the "new" pointer. As for, int part, iI already change but I received all these cant fixed error

  4. #19
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    Quote Originally Posted by Elysia View Post
    Stop avoiding the problem and learn how to do it properly.
    This is basics of basics. If you cannot master this, then you are not a programmer and cannot hope to be.
    I still havent learnt composition in school . Of course i dun know.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by evildotaing View Post
    I am asking user to input the size of the queue(eg. 20, 30, 40) and the program would used the size from the user. Of course i need the "new" pointer...
    No, you don't.

    ...As for, int part, iI already change but I received all these cant fixed error
    Fix the abovementioned problems and then repost your code.

    Quote Originally Posted by evildotaing View Post
    I still havent learnt composition in school . Of course i dun know.
    This is less about composition and more about simply using data types. It isn't difficult!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    The first problem i encounter, if I change it to mydata instead of int in the queue.h to declare the list, all my "list" in main.cpp would be called as undeclared. So if it is right to change it. Give me some hints.

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Did you take care of the other problems mentioned earlier, such as void main?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    received more error if i declared a list[array] in main.cpp. Which problem must I fixed first?

  9. #24
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Look back at my post #2, and work out how to make your code have the same visibility of the myData declaration.

    It's a really simple one-line change that ought to really cut down on the amount of errors.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #25
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    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];
        }
        /*
        else
        {
            return 0;
        }
        */
    }
     
    int Queue::Myback(void) const
    {
        if (!IsFullQueue())
        {
            return list[back];
        }
        /*
        else
        {
            return 0;
        }
        */
    }
     
     
    void Queue::addQueue(myData )
    {
        if (!IsFullQueue())
        {
            back = (back + 1) % maxQueuesize;
            count++;
            list[back] = element;
        }
     
        else
        {
            cout << "Unable to add a full queue: " << endl;
        }
    }
     
    myData Queue::removeQueue(void)
    {
        if (!IsEmptyQueue())
        {
            count --;
            front = (front + 1) % maxQueuesize;
        }
        else
        {
            cout << "Cannot remove from an emty queue." << endl;
        }
    }
     
    Queue::Queue(int size)
    {
        if (size <= 0)
        {
            cout << "Size must be positive." << endl;
            //cout << "An array of size 10 is created for you." << endl;
            //maxQueuesize = 10;
        }
        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 " << front << endl;
        cout << "Your queue number is #" << back << endl;
    }
    Because since some of the class function variables/func has been changed to myData, so I change it together with the queue.cpp, i think it is the queue.cpp above where i had write wrong code but not sure how to correct it.

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Go back to basics and re-learn the language properly.
    And fix what we have told you to fix.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    I know that the class myData is to insert 2 variables string and a int value(something like a struct) so that all the other functions in queue.cpp can be used to group those 2 variables and solve my problem. But, i not sure where I had done wrong in queue.cpp here which I think I make a major mistake.

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Make three files:

    Code:
    // main.cpp:
    int main()
    {
    	foo(10);
    }
    
    // Test.h:
    struct XTest {};
    
    // foo.cpp:
    void foo(int n) {}
    Now change foo to accept a XTest struct and make it compile.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #29
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    Quote Originally Posted by Elysia View Post
    Make three files:

    Code:
    // main.cpp:
    int main()
    {
    	foo(10);
    }
    
    // Test.h:
    struct XTest {};
    
    // foo.cpp:
    void foo(int n) {}
    Now change foo to accept a XTest struct and make it compile.
    I dun understand this part

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What is so difficult to understand? I want to make this code work:
    Code:
    // main.cpp:
    int main()
    {
    	XTest test;
    	foo(test);
    }
     
    // Test.h:
    struct XTest {};
     
    // foo.cpp:
    void foo(int n) {}
    Modify it in such a way that it will compile.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

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. queue
    By hokuokekai in forum C++ Programming
    Replies: 1
    Last Post: 10-15-2010, 09:19 AM
  3. Help me about queue
    By tqn_hnvietnam in forum C Programming
    Replies: 7
    Last Post: 09-29-2008, 08:37 PM
  4. ADT queue
    By ^xor in forum C Programming
    Replies: 4
    Last Post: 06-15-2005, 05:43 AM
  5. Queue and Priority Queue
    By Pamela in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2001, 11:09 PM