I have a homework assignment that I just cannot figure out. I would be grateful of any help.

The assignment is:

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.
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.

#include <iostream>

using namespace std;

class Queue {
    int array[maxQ];

That's all the code I've got. How do you declare constructors?

6 Years
Discussion Span
Last Post by Zeeshan Cheema

This is actually a clear-cut easy to follow assignment. Your instructor did all the thinking for you. There is nothing left up to your imagination; all you have to do is follow directions.

class Queue

     Queue(int& q);
     void add(int);
     void take();


     int array[100];

You will probably end up adding more stuff to this class, like menu() and display() functions for example.. what I outlined for you is the bear minimum required of your assignment.

Edited by Clinton Portis: n/a

class Queue
     Queue(int& q){maxQ=q};
     void add(int){//add the parameter of this function to ith element of array};
     void take();
     int array[100];

Edited by __avd: Added [code] tags. Do wrap your programming code blocks within [code] ... [/code] tags.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.