Help me with this please is for tomorrrow

When you play a board or card game or when you use a shared computing resource, you get a turn and then wait
until everyone else has had a turn. Although the number of players in a game remains relatively static, the
number of users of a shared computing service fl uctuates. Let’s assume that this fl uctuation will occur.
Design an ADT that keeps track of turns within a group of people. You should be able to add or delete people
and determine whose turn occurs now.
Begin with a given group of people; assign these people an initial order. (This order can be random or
specifi ed by the user.) The fi rst new person joining the group should get a turn after all others have had an equal
number of turns. Each subsequent new person should get a turn after the person who joined the group most
recently has had a turn.
Also design an ADT to represent a person. (You can be conservative with the amount of data that this ADT
contains.) The data that your fi rst ADT stores is made up of instances of the ADT person.
Implement your ADTs as C++ classes. Write a program that uses—and therefore tests—your ADTs completely.
Your program should process several insertion and deletion operations, and demonstrate that people are
given turns correctly.
Kind of waited until last minute for this post didn't you? Let us know if you got an extension and if you still need help with it.
If you really need help, I can help you work this problem. I will NOT solve it for you, though.

Regards,
Joe
sparkprogrammer@gmail.com
i need to doe this until next week, let me know how you can help me
Node.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//#pragma once
//#ifndef _NODE
//#define _NODE
#pragma once
using namespace std;

template < class ItemType>
class Node
{
private:
	ItemType item; // A data item
	Node<ItemType>* next; // Pointer to next node
public:
	Node();
	Node(const ItemType& anItem);
	Node(const ItemType& anItem, Node<ItemType>* nextNodePtr);
	void setItem(const ItemType& anItem);
	void setNext(Node<ItemType>* nextNodePtr);
	ItemType getItem() const;
	Node<ItemType>* getNext() const;
}; // end Node
//#include "Node.cpp"
//#endif



template < class ItemType>
Node<ItemType>::Node() : next(nullptr)
{
} // end default constructor
template < class ItemType>
Node<ItemType>::Node(const ItemType& anItem) : item(anItem), next(nullptr)
{
} // end constructor
template < class ItemType>
Node<ItemType>::Node(const ItemType& anItem, Node<ItemType>* nextNodePtr) :
item(anItem), next(nextNodePtr)
{
} // end constructor
template < class ItemType>
void Node<ItemType>::setItem(const ItemType& anItem)
{
	item = anItem;
} // end setItem
template < class ItemType>
void Node<ItemType>::setNext(Node<ItemType>* nextNodePtr)
{
	next = nextNodePtr;
} // end setNext
template < class ItemType>
ItemType Node<ItemType>::getItem() const
{
	return item;
} // end getItem
template < class ItemType>
Node<ItemType>* Node<ItemType>::getNext() const
{
	return next;
} // end getNext

ListInterface.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef _LIST_INTERFACE
#define _LIST_INTERFACE
using namespace std;

template < class ItemType>
class ListInterface
{
public:
	/** Sees whether this list is empty.
	@return True if the list is empty; otherwise returns false. */
	virtual bool isEmpty() const = 0;
	/** Gets the current number of entries in this list.
	@return The integer number of entries currently in the list. */
	virtual int getLength() const = 0;
	/** Inserts an entry into this list at a given position.
	@pre None.
	@post If 1 <= position <= getLength() + 1 and the insertion is
	successful, newEntry is at the given position in the list,
	other entries are renumbered accordingly, and the returned
	value is true.
	@param newPosition The list position at which to insert newEntry.
	@param newEntry The entry to insert into the list.
	@return True if insertion is successful, or false if not. */
	virtual bool insert(int newPosition, const ItemType& newEntry) = 0;
	/** Removes the entry at a given position from this list.
	@pre None.
	@post If 1 <= position <= getLength() and the removal is successful,
	the entry at the given position in the list is removed, other
	items are renumbered accordingly, and the returned value is true.
	@param position The list position of the entry to remove.
	@return True if removal is successful, or false if not. */
	virtual bool remove(int position) = 0;
	/** Removes all entries from this list.
	@post List contains no entries and the count of items is 0. */
	virtual void clear() = 0;
	/** Gets the entry at the given position in this list.
	@pre 1 <= position <= getLength().
	@post The desired entry has been returned.
	@param position The list position of the desired entry.
	@return The entry at the given position. */
	virtual ItemType getEntry(int position) const = 0;
	/** Replaces the entry at the given position in this list.
	@pre 1 <= position <= getLength().
	@post The entry at the given position is newEntry.
	@param position The list position of the entry to replace.
	@param newEntry The replacement entry. */
	virtual void setEntry(int position, const ItemType& newEntry) = 0;
}; // end ListInterface
#endif 
LinkedBag.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//#ifndef _LINKED_BAG
//#define _LINKED_BAG
#pragma once
#include "BagInterface.h"
#include "Node.h"
using namespace std;
#include<iostream>
template < class ItemType>
class LinkedBag : public BagInterface<ItemType>
{
private:
	Node<ItemType>* headPtr; // Pointer to first node
	int itemCount; // Current count of bag items
	// Returns either a pointer to the node containing a given entry
	// or the null pointer if the entry is not in the bag.
	Node<ItemType>* getPointerTo(const ItemType& target) const;
public:
	LinkedBag();
	LinkedBag(const LinkedBag<ItemType>& aBag); // Copy constructor
	virtual ~LinkedBag(); // Destructor should be virtual
	int getCurrentSize() const;
	bool isEmpty() const;
	bool add(const ItemType& newEntry);
	bool remove(const ItemType& anEntry);
	void clear();
	void displayBag();
	bool contains(const ItemType& anEntry) const;
	int getFrequencyOf(const ItemType& anEntry) const;
	vector<ItemType> toVector() const;
}; // end LinkedBag
//#include "LinkedBag.cpp"
//#endif

////////////////////////////////////////////////////////////////////////////////////






template < class ItemType>
LinkedBag<ItemType>::LinkedBag() : headPtr(nullptr), itemCount(0)
{
} // end default constructor

template < class ItemType>
bool LinkedBag<ItemType>::add(const ItemType& newEntry)
{
	// Add to beginning of chain: new node references rest of chain;
	// (headPtr is nullptr if chain is empty)
	Node<ItemType>* newNodePtr = new Node<ItemType>();
	newNodePtr->setItem(newEntry);
	newNodePtr->setNext(headPtr); // New node points to chain
	headPtr = newNodePtr; // New node is now first node
	itemCount++;
	return true;
} // end add

template < class ItemType>
vector<ItemType> LinkedBag<ItemType>::toVector() const
{
	vector<ItemType> bagContents;
	Node<ItemType>* curPtr = headPtr;
	int counter = 0;
	while ((curPtr != nullptr) && (counter < itemCount))
	{
		bagContents.push_back(curPtr->getItem());
		curPtr = curPtr->getNext();
		counter++;
	} // end while
	return bagContents;
} // end toVector

template < class ItemType>
bool LinkedBag<ItemType>::isEmpty() const
{
	return itemCount == 0;
} // end isEmpty
template < class ItemType>
int LinkedBag<ItemType>::getCurrentSize() const
{
	return itemCount;
} // end getCurrentSize

template < class ItemType>
int LinkedBag<ItemType>::getFrequencyOf(const ItemType& anEntry) const
{
	int frequency = 0;
	int counter = 0;
	Node<ItemType>* curPtr = headPtr;
	while ((curPtr != nullptr) && (counter < itemCount))
	{
		if (anEntry == curPtr->getItem())
		{
			frequency++;
		} // end if
		counter++;
		curPtr = curPtr->getNext();
	} // end while
	return frequency;
} // end getFrequencyOf

// Returns either a pointer to the node containing a given entry
// or the null pointer if the entry is not in the bag.
template < class ItemType>
Node<ItemType>* LinkedBag<ItemType>::
getPointerTo(const ItemType& target) const
{
	bool found = false;
	Node<ItemType>* curPtr = headPtr;
	while (!found && (curPtr != nullptr))
	{
		if (target == curPtr->getItem())
			found = true;
		else
			curPtr = curPtr->getNext();
	} // end while
	return curPtr;
} // end getPointerTo

//The definition of the method contains is straightforward :
template < class ItemType>
bool LinkedBag<ItemType>::contains(const ItemType& anEntry) const
{
	return (getPointerTo(anEntry) != nullptr);
} // end contains

template < class ItemType>
bool LinkedBag<ItemType>::remove(const ItemType& anEntry)
{

	Node<ItemType>* entryNodePtr = getPointerTo(anEntry);
	bool canRemoveItem = !isEmpty() && (entryNodePtr != nullptr);
	if (canRemoveItem)
	{
		// Copy data from first node to located node
		entryNodePtr->setItem(headPtr->getItem());
		// Delete first node
		Node<ItemType>* nodeToDeletePtr = headPtr;
		headPtr = headPtr->getNext();
		// Return node to the system
		nodeToDeletePtr->setNext(nullptr);
		delete nodeToDeletePtr;
		nodeToDeletePtr = nullptr;
		cout << "Removing" << endl;
		itemCount--;
	} // end if
	return canRemoveItem;
} // end remove

template < class ItemType>
void LinkedBag<ItemType>::clear()
{
	Node<ItemType>* nodeToDeletePtr =NULL;
	while (headPtr != nullptr)
	{
		Node<ItemType>* nodeToDeletePtr = headPtr;
		headPtr = headPtr->getNext();
		// Return node to the system
		nodeToDeletePtr->setNext(nullptr);
		delete nodeToDeletePtr;
	} // end while
	// headPtr is nullptr
	nodeToDeletePtr = nullptr;
	itemCount = 0;
} // end clear

template < class ItemType>
LinkedBag<ItemType>::~LinkedBag()
{
	clear();
} // end destructor
template < class ItemType>
void LinkedBag<ItemType>::displayBag()
{
	cout << "The bag contains " << this->getCurrentSize()
		<< " items:" << endl;
	Node<ItemType>*curPtr=this->headPtr;
	Node<ItemType>*curPtr2 = this->headPtr;
	int counter=0;
	cout <<endl<< "Economy class" << endl;
	cout << "--------------------------------------------" << endl << endl;
	while (curPtr2 != nullptr)
	{
		if (curPtr2->getItem().getSitn() >5){
			cout << curPtr2->getItem();

		}
		curPtr2 = curPtr2->getNext();
		counter++;
	}
	cout <<endl<< "First Class" << endl;
	cout << "--------------------------------------------" << endl << endl;
	while(curPtr!=nullptr)
	{
		if (curPtr->getItem().getSitn() <= 5){
			cout << curPtr->getItem();
			
		}
		curPtr = curPtr->getNext();
			counter++;
	}
	
	cout << endl << endl;
} 

template < class ItemType>
LinkedBag<ItemType>::LinkedBag(const LinkedBag<ItemType>& aBag)
{
	itemCount = aBag->itemCount;
	Node<ItemType>* origChainPtr = aBag->headPtr;
		if (origChainPtr == nullptr)
			headPtr = nullptr; // Original bag is empty; so is copy
		else
		{
			// Copy first node
			headPtr = new Node<ItemType>();
			headPtr->setItem(origChainPtr->getItem());
			// Copy remaining nodes
			Node<ItemType>* newChainPtr = headPtr; // Last-node pointer
			while (origPtr != nullptr)
			{
				origChainPtr = origChainPtr->getNext(); // Advance pointer
				// Get next item from original chain
				ItemType nextItem = origChainPtr->getItem();
				// Create a new node containing the next item
				Node<ItemType>* newNodePtr = new Node<ItemType>(nextItem);
				// Link new node to end of new chain
				newChainPtr->setNext(newNodePtr);
				// Advance pointer to new last node
				newChainPtr = newChainPtr->getNext();
			} // end while
			newChainPtr->setNext(nullptr); // Flag end of new chain
		} // end if
} // end copy constructor





Last edited on
BagInterface.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49


#ifndef ArrayBag_BagInterface_h
#define ArrayBag_BagInterface_h

#include <vector>
using namespace std;

template<class ItemType> class BagInterface
{
public:
	/** Gets the current number of entries in this bag.
	@return The integer number of entries currently in the bag. */
	virtual int getCurrentSize() const = 0;
	/** Sees whether this bag is empty.
	@return True if the bag is empty, or false if not. */
	virtual bool isEmpty() const = 0;
	/** Adds a new entry to this bag.
	@post If successful, newEntry is stored in the bag and
	the count of items in the bag has increased by 1.
	@param newEntry The object to be added as a new entry. @return True if addition was successful, or false if not. */
	virtual bool add(const ItemType& newEntry) = 0;

	/** Removes one occurrence of a given entry from this bag, if possible.
	@post If successful, anEntry has been removed from the bag and the count of items in the bag has decreased by 1.
	@param anEntry The entry to be removed.
	@return True if removal was successful, or false if not. */
	virtual bool remove(const ItemType& anEntry) = 0;
	/** Removes all entries from this bag.
	@post Bag contains no items, and the count of items is 0. */
	virtual void clear() = 0;
	/** Counts the number of times a given entry appears in bag. @param anEntry The entry to be counted.
	@return The number of times anEntry appears in the bag. */
	virtual int getFrequencyOf(const ItemType& anEntry) const = 0;

	/** Tests whether this bag contains a given entry.
	@param anEntry The entry to locate.
	@return True if bag contains anEntry, or false otherwise. */
	virtual bool contains(const ItemType& anEntry) const = 0;
	/** Empties and then fills a given vector with all entries that are in this bag.
	@return A vector containing all the entries in the bag. */
	virtual vector<ItemType> toVector() const = 0;

	virtual ~BagInterface(){}
}; // end BagInterface


#endif
ArrayBag.h


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
//  Header.h
//  ArrayBag
//
//

#ifndef ArrayBag_Header_h
#define ArrayBag_Header_h

#include "BagInterface.h"
#include<iostream>

using namespace std;
template<class ItemType>
class ArrayBag : public BagInterface<ItemType>
{
protected:
	static const int DEFAULT_CAPACITY = 6; 	// Small size to test for a full bag
	ItemType items[DEFAULT_CAPACITY]; 		// Array of bag items
	int itemCount;	// Current count of bag items 
	int maxItems;   // Max capacity of the bag

	// Returns either the index of the element in the array items that 
	// contains the given target or -1, if the array does not contain 
	// the target.
	
	int getIndexOf(const ItemType& target) const;
	
public:	
	bool add(const ItemType& newEntry);
	ArrayBag();
	
	int getCurrentSize() const;
	bool isEmpty() const;
	bool remove(const ItemType& anEntry);
	void clear();
	bool contains(const ItemType& anEntry) const;
	int getFrequencyOf(const ItemType& anEntry) const;
	vector<ItemType> toVector() const;
	//ArrayBag<ItemType> operator+(ArrayBag<ItemType> & anBag);
	/*friend ostream& operator<<(ostream & out, const ArrayBag<ItemType> & Term);
	friend istream& operator>>(istream & in, ArrayBag<ItemType> & Term);*/
	void crateBag();
	
	virtual ~ArrayBag();
	// end ArrayBag
};

template<class ItemType>
int ArrayBag<ItemType>::getIndexOf(const ItemType& target) const
	{
		bool found = false;
		int result = -1;
		int searchIndex = 0;

		// If the bag is empty, itemCount is zero, so loop is skipped
		while (!found && (searchIndex < itemCount))
		{
			if (items[searchIndex] == target)
			{
				found = true;
				result = searchIndex;
			}
			else
			{
				searchIndex++;
			}//end if				
		}//end while
		return result;
	}
template<class ItemType>
bool ArrayBag<ItemType>::add(const ItemType& newEntry)
	{
		bool hasRoomToAdd = (itemCount < maxItems);
		if (hasRoomToAdd)
		{
			items[itemCount] = newEntry;
			itemCount++;
		} // end if
		return hasRoomToAdd;
	}// end add
template<class ItemType>
ArrayBag<ItemType>::ArrayBag()
	{
		itemCount = 0;
		maxItems = DEFAULT_CAPACITY;

	}
template<class ItemType>


int ArrayBag<ItemType>::getCurrentSize() const
	{
		return itemCount;
	}// end getCurrentSize

	template<class ItemType>
	bool ArrayBag<ItemType>::isEmpty() const
	{
		return itemCount == 0;
	}// end isEmpty

	template<class ItemType>
	bool ArrayBag<ItemType>::remove(const ItemType& anEntry)
	{
		int locatedIndex = getIndexOf(anEntry);
		bool canRemoveItem = !isEmpty() && (locatedIndex > -1);
		if (canRemoveItem)
		{
			itemCount--;
			items[locatedIndex] = items[itemCount];
		}
		return canRemoveItem;
	}// end remove

	template<class ItemType>
	void ArrayBag<ItemType>::clear()
	{
		itemCount = 0;
	}// end Clear

	template<class ItemType>
	bool ArrayBag<ItemType>::contains(const ItemType& anEntry) const
	{
		bool found = false;
		int curIndex = 0; // Current array index
		while (!found && (curIndex < itemCount))
		{

			if (anEntry == items[curIndex])
			{
				found = true;
			} // end if
			curIndex++; // Increment to next entry
		} // end while
		return found;
	}   // end contains

	template<class ItemType>
	int ArrayBag<ItemType>::getFrequencyOf(const ItemType& anEntry) const
	{
		int frequency = 0;
		int curIndex = 0; // Current array index

		while (curIndex < itemCount)
		{
			if (items[curIndex] == anEntry) {
				frequency++;
			} // end if
			curIndex++; // Increment to next entry
		} // end while
		return frequency;
	}//end getFrequencyOf
	template<class ItemType>
	ostream& operator<<(ostream & out, const ArrayBag<ItemType> & Terms)
	{
		for(int i=0;i<Terms.itemCount;i++)
		{
			cout<<Terms.items[i];
		}
		return out;
	}
	/*template<class ItemType>
	ArrayBag<ItemType> operator+(ArrayBag<ItemType> & anBag)
	{
			
			

	}*/
	template<class ItemType>
	void ArrayBag<ItemType>::crateBag()
	{
		Term temp;
		for(int i=0;i<this->itemCount;i++)
		{
			cin>>temp;
			add(temp);
		}
		
	}
	
	
	template<class ItemType>
	vector<ItemType> ArrayBag<ItemType>::toVector() const
	{
		vector<ItemType> bagContents;
		for (int i = 0; i < itemCount; i++)
			bagContents.push_back(items[i]);

		return bagContents;
	}
	template<class ItemType>
	ArrayBag<ItemType>::~ArrayBag(){}
#endif 
this are the classes to use in this program
Topic archived. No new replies allowed.