1,105,633 Community Members

class/constructors/arrays...Homework Assignment

Member Avatar
penguins10
Newbie Poster
5 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

#include <iostream>

using namespace std;

class Queue {
private:
    int array[maxQ];

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

Member Avatar
daviddoria
Posting Virtuoso
1,968 posts since Feb 2008
Reputation Points: 334 [?]
Q&As Helped to Solve: 204 [?]
Skill Endorsements: 8 [?]
Featured
 
0
 

I suggest you work through this excellent tutorial:
http://www.cplusplus.com/doc/tutorial/

before attempting that assignment.

Member Avatar
Clinton Portis
Practically a Posting Shark
831 posts since Oct 2005
Reputation Points: 211 [?]
Q&As Helped to Solve: 120 [?]
Skill Endorsements: 8 [?]
 
0
 

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
{
     public:

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

     private:

     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.

Member Avatar
Zeeshan Cheema
Newbie Poster
2 posts since Dec 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
class Queue
{
     public:
     Queue(){maxQ=100};
     Queue(int& q){maxQ=q};
     void add(int){//add the parameter of this function to ith element of array};
     void take();
     protected:
     int array[100];
};
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: