Hi, i have no idea how to go about doing this iv tried coding it a bit but just get very confused! if anyone could give me a hand or show me some sample code would be great.

Thank you


Create a program which:
Implements a class called Queue: The class should contain an array of maxQ integers.
There should be two constructors:
One that takes no argument creates a Queue object of maxQ=100 values.
One that takes a parameter q and creates a Queue object of maxQ=q values.
Queue should also have:
a function/method add(int) by which a user can add an integer value to a Queue object.
a function/method take() by which a user can read from a Queue object the first integer that was entered into it. After being read the integer should not be in the queue anymore.
In the main():
create a Queue object of maxQ=20
keep on asking the user whether (s)he wants to 1) add integers to the queue; 2) take integers from the queue; 3) exit.
when the user is prompted for the choice above (s)he should also be shown how many integers are currently in the queue.

Suggestions:
You may have 2 values stored inside class Queue:
start: the position of the first element that was entered
end: the position of the last element entered
When an element is added through add(int), end should advance by one. If this brings it past the end of the array, it should pan to the beginning.
When an element is taken through take():
if no element is in the queue, 0 should be returned and nothing else should happen
if the queue is not empty, the first element entered (the one at position start) should be returned, and start should advance by one. If this brings it past the end of the array, it should pan to the beginning.

Recommended Answers

All 3 Replies

Which component is giving you the most trouble? The instructions seem to be a good starting point. Try to implement at least some portion of it (class, two constructors, etc.) and post your code and someone will help.

#include <iostream>
using namespace std;

class Queue {
public:
    int array[maxQ];
    //Declare constructor
    construc1();

    construc2();

    //declare function
    int add() {
        int c = 0;
        //input values to array
        while (c< maxQ) {
            cout<<"\nPlease enter a value:";
            cin>>array[c];

            c++;
    }

        int take() {






        }


};

int main()
{






    return 0;
}

Thats what i wrote so far but just getting really confused and don't think im dong it correctly!

thank you

Array should be a pointer to int, because you're going to instantiate it to a certain size in the constructors. As you probably know, your syntax on the constructors is not correct.

Follow the directions:

There should be two constructors:
One that takes no argument creates a Queue object of maxQ=100 values.
One that takes a parameter q and creates a Queue object of maxQ=q values.

Note that maxQ should probably be a private member variable.

If for some reason you are trying to do this class and pick up C++ at the same time, run through some tutorials before you take this on. The time invested now will be returned when you don't have to keep looking up fundamentals.

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.