Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please i need this done in C++ language that compiles and works properly. Also please don't use vectors. The Magic Bag The ma gic bag

Please i need this done in C++ language that compiles and works properly. Also please don't use vectors.

image text in transcribed

The Magic Bag The ma gic bag data type will be implemented as follows Objects can be inserted into the magic bag using the MagicBag::insert(item) member function. The magic bag can hold any number of items, within the bounds of the available RAM. Duplicate items are allowed Objects are removed from the magic bag using the MagicBag::draw() member function. This function returns a random item and removes it from the bag. The returned item should be randomized In other words, if there are 5 items in the bag, and only one of them is a 7, then there should be a 1 in 5 chance of drawing a 7 with the draw) function. If the bag is empty, the drawo function should throw an exception. .You can check if an object is in the bag using MagicBag: :peek (item), which should return 0 if there is no item in the bag matching the item parameter. If there are items matching the item parameter in the bag, the number (count) of matching items should be returned .You can print a magic bag using the MagicBag: :print (ostream&) member function. This function should print to any ostream you pass to it (cout, cerr, etc.). You should be able to assign the contents of a MagicBag using the operator. This should result in a copy of the magic bag that is not linked to the original bag. In other words, if a and b are magic bags the line "a = b;" should result in bags a and b having the same contents. If I then draw elements from bag b, this should not change the contents of bag a .You should begin by constructing a magic bag that holds integers. For additional credit, you can create a template so that the magic bag can hold any primitive data type (see below for grading details). You can implement the magic bag using an array, a linked, list, or any other data structure that you feel is appropriate. You need to design and implement the underlying data structure yourself. You may not for example, use C++ standard template library vectors for the underlying data structure You will be provided with a main program for testing your magic bag No points will be awarded for submissions that do not compile No points will be awarded for line items that produce a segmentation fault

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions