Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include using namespace std; class BagDyn { public: BagDyn(); // construction bool Add(int n); // Add, true if successfully added bool Remove(int

image text in transcribed

#include #include #include #include

using namespace std;

class BagDyn { public: BagDyn(); // construction bool Add(int n); // Add, true if successfully added bool Remove(int n); unsigned int getCapacity(); unsigned int getSize(); bool Search(int s); bool isEmtpy(); void ListAll();

private: int *data; unsigned int size; unsigned int capacity;

};

BagDyn::BagDyn() { data = NULL; cout > capacity; size = 0; data = new int[capacity]; if (data == NULL) { cout

}

unsigned int BagDyn::getCapacity() { return capacity; }

unsigned int BagDyn::getSize() { return size; }

bool BagDyn::Search(int s) { for (int i = 0; i

return false; }

bool BagDyn::isEmtpy() { if (size == 0) return true; return false; }

bool BagDyn::Add(int n) { if (size == capacity) return false;

for (int i = 0; i

return true; }

void BagDyn::ListAll() { if (size == 0) { cout

for (int i = 0; i

cout

}

bool BagDyn::Remove(int n) { if (isEmtpy() == true) return false;

for (int i = 0; i

int main() { BagDyn aBag; aBag.ListAll(); aBag.Add(5); aBag.Add(7); aBag.Add(1); aBag.ListAll(); aBag.Add(8); aBag.Add(17); aBag.Add(5); aBag.ListAll();

if (aBag.Search(8) == true) cout

aBag.Remove(17); aBag.ListAll(); aBag.Remove(5); aBag.ListAll(); cout

system("pause");

}

This activity is based on bag implementation using "new" operator (BagDynMemAlloc.cpp) Your tasks are to modify BagDyn() class given in BagDynMemAlloc.cpp, to allow up to three duplicates of same item. Initially create a bag with the capacity of 10 items. Ask user to input an item to bag. If the count of current item is already three, then do not add this item to the bag. A sample run given below. A bag with capacity of 10 is ready... Enter a number: 5 > 5 Enter a number: 3 > 5, 3 Enter a number: 5 > 5, 3, 5 Enter a number: 7 > 5, 3, 5, 7 Enter a number: 5 > 5, 3, 5, 7, 5 Enter a number: 5 Bag has already three 5s. > 5, 3, 5, 7, 5 Enter a number: 1 > 5, 3, 5, 7, 5, 1 Enter a number: 0 > 5, 3, 5, 7, 5, 1, 0 Enter a number: 0 > 5, 3, 5, 7, 5, 1, 0, 0 Enter a number: 0 > 5, 3, 5, 7, 5, 1, 0, 0, 0 Enter a number: 0 Bag has already three es. > 5, 3, 5, 7, 5, 1, 0, 0, A negative user entry quits the program. 2 Enter a number: -1 Bye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions

Question

6. Discuss the steps involved in conducting a task analysis.

Answered: 1 week ago

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago