Question: Use the ArrayBag class structure. Implement a menu of options that uses the member functions defined in the class. Search based on an ID you

Use the ArrayBag class structure.

Implement a menu of options that uses the member functions defined in the class.

Search based on an ID you assign for each speaker.

Use the ArrayBag class structure. Implement a menu of options that uses

ArrayBag.h

#ifndef _ARRAY_BAG

#define _ARRAY_BAG

#include "BagInterface.h"

template

class ArrayBag : public BagInterface

{

private:

static const int DEFAULT_CAPACITY = 6;

ItemType items[DEFAULT_CAPACITY];

int itemCount;

int maxItems

int getIndexOf(const ItemType& target) const;

public:

ArrayBag();

int getCurrentSize() const;

bool isEmpty() const;

bool add(const ItemType& newEntry);

bool remove(const ItemType& anEntry);

void clear();

bool contains(const ItemType& anEntry) const;

int getFrequencyOf(const ItemType& anEntry) const;

vector toVector() const;

};

#include "ArrayBag.cpp"

#endif

ArrayBag.cpp

#include "ArrayBag.h"

#include

template

ArrayBag::ArrayBag(): itemCount(0), maxItems(DEFAULT_CAPACITY)

{

}

template

int ArrayBag::getCurrentSize() const

{

return itemCount;

}

template

bool ArrayBag::isEmpty() const

{

return itemCount == 0;

}

template

bool ArrayBag::add(const ItemType& newEntry)

{

bool hasRoomToAdd = (itemCount

if (hasRoomToAdd)

{

items[itemCount] = newEntry;

itemCount++;

}

return hasRoomToAdd;

}

template

bool ArrayBag::remove(const ItemType& anEntry)

{

int locatedIndex = getIndexOf(anEntry);

bool canRemoveItem = !isEmpty() && (locatedIndex > -1);

if (canRemoveItem)

{

itemCount--;

items[locatedIndex] = items[itemCount];

}

return canRemoveItem;

}

template

void ArrayBag::clear()

{

itemCount = 0;

}

template

int ArrayBag::getFrequencyOf(const ItemType& anEntry) const

{

int frequency = 0;

int curIndex = 0;

while (curIndex

{

if (items[curIndex] == anEntry)

{

frequency++;

}

curIndex++;

}

return frequency;

}

template

bool ArrayBag::contains(const ItemType& anEntry) const

{

return getIndexOf(anEntry) > -1;

}

template

vector ArrayBag::toVector() const

{

vector bagContents;

for (int i = 0; i

bagContents.push_back(items[i]);

return bagContents;

}

template

int ArrayBag::getIndexOf(const ItemType& target) const

{

bool found = false;

int result = -1;

int searchIndex = 0;

while (!found && (searchIndex

{

if (items[searchIndex] == target)

{

found = true;

result = searchIndex;

}

else

{

searchIndex++;

}

}

return result;

}

BagInterface.h

#ifndef _BAG_INTERFACE

#define _BAG_INTERFACE

#include

using namespace std;

template

class BagInterface

{

public:

virtual int getCurrentSize() const = 0;

virtual bool isEmpty() const = 0;

virtual bool add(const ItemType& newEntry) = 0;

virtual bool remove(const ItemType& anEntry) = 0;

virtual void clear() = 0;

virtual int getFrequencyOf(const ItemType& anEntry) const = 0;

virtual bool contains(const ItemType& anEntry) const = 0;

virtual vector toVector() const = 0;

};

#endif

9. Speakers' Bureau structure to store the following data about a speaker: Name Telephone Number Speaking Topic Fee Required The program should use an array of at least 10 structures. It should let the user enter data into the array, change the contents of any element, and display all the data store in the array. The program should have a menu-driven user interface. Input Validation: When the data for a new speaker is entered, be sure the user enters data for all the fields. No negative amounts should be entered for a speaker's fee

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!