Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c ++ instructions are there on the first photo. The cide cane with the assignment its C++ please us the bagarray code to make
in c ++ instructions are there on the first photo. The cide cane with the assignment
its C++
please us the bagarray code to make 3 new methods for that BagArray code sttached(the black background picture that looks like code)
You will use the array bag code that we reviewed in the text book. This code is provided with this assignment. In this code I have added one new method to the class for you to use as a guide. You should remove all traces of the "doSomething" method in all the files before you submit your assignment. You will write 3 new methods in the ArrayBag class: 1. bubblesort - a method to sort the array in ascending order using the bubble sort 2. binarySearchiterative - a repetitive version of the binary search 3. binarySearchRecursive - a recursive version of the binary search (You should use a helper method that calls the recursive method so the client code does not have to provide the extra parameters. Client calls to both of the search methods should be identical other than the method name.) Load your bag with some initial values, but do not fill it completely. Your client code should give the user the option to: 1. display the contents of the bag using the class method "tovector" 2. add values to the bag 3. remove values from the bag 4. sort the bag 5. search for a value using their choice of either the iterative search or the recursive search - both need t be tested Allow the user to keep doing these things until they are done. Do not automatically sort the bag if the user chooses to search. Your program should give the user a message telling them they must first sort the bag before they can search. You must think of a way to detect programatically that the array has not been sorted. You decide what the user interface will be. Make it clear and easy to use. It can be very basic; nothing fancy. A menu driven program works well. Each value in your array should be unique - no value will appear in the array multiple times. Your array elements can be any data type the client code wants to use - use a template class put in place in the code provided. You can write your client code to process a bag holding any data type you want. Write your client code in a modular, structured fashion. Make sure you perform input validation where appropriate. This program should be bullet-proof and well documented. I am expecting code from a programmer who is in their third semester of writing software. You will submit the following: All of program source and header files compressed into a zip file (.zip). Name your zip file "lab1_Firstname_Lastname". You decide what to name the other files. Do not include exe files. Lab Grade Points Labs will be graded on the following: Comments Including: - Program description (comment block at top of program) - Function descriptions for every function other than main() (see function heading below) - Comments at major algorithm steps (at a minimum) Followed directions Correct output. Structured program design Meaningful identifier names Meaningful identifier names Function heading should look similar to this: NOTE - The "NEVER" list of rules: - You will NEVER use break, exit, return, pass, continue or anything to leave a loop (or iteration), function, or other construct prematurely, unless it is part of the structure as in a case statement. - You will NEVER have a function call itself, unless it is intentional recursion. - You will NEVER use global variables. However, you may use global constants if it is appropriate and they are used properly. - You will have only one return statement in a function. (Exception - Multiple return statements may be necessary in a recursive function.) \#itndef ARRAY_BAG_- \#define ARRAY_BAG_ \#include \#include "ArrayBag.h" using namespace std; void bagTester(ArrayBagcint>\& bag); int main() II This is one way you can get values in the bag. If You could also read the values from a file. I/ You pick - but you should load up the bag with values. ArrayBag bag; int items []={1,33,6,9,2,65,4,29,5,8,39,88,7,25,51,3,99,14,11,10}; cout "Adding positive integers to the bag: " e endi; for (int i=0;i\& bag) If This is just some sample code processing the bag. If You should remove this function from your program completely. cout "The bag is not empty; isempty: returns " bag.isempty() endl; cout "About to clear the bag, "; bag.clear(); cout "isEmpty: returns " bag.isempty() end1; 1/ end bagTester Baglnterface Mifndef BAG_INTERFACE_ \#define BAO_INTERFACE_ Ainclude svectors templatecclass ItenType> class Baginterface t public: I/ Example of adding a new nethod virtual void doSomething( =; II Gets the current number of entries in this bag. If Returns the integer number of entries currentiy in the bag virtual int getCurrentsize() const = o; II sees whether this bag is empty. II Returns True if the bag is empty, or false if not virtual bool isempty() const =0; II Adds a new entry to this bag. If If successful, newEntry is stored in the bag and 1/ the count of items in the bag has inereased by 1. If Input: newentry The object to bo added as a new entry. 1/ Returns True if addition was successful, or false if not virtual bool add(const ItemType\& newentry) =; If Removes one occurrence of a given entry from this bag, If if possible. II If successful, anEntry has been removed from the bag 11 and the count of items in the bag has decreased by 1. If Inputi anEntry the entry to be removed. II Returns: True if removal was successfu1, or false if not virtual bool remove(const ItemType\& anEntry) =0; II Resoves all entries from this bag. If Result: Bag contains no items, and the count of items is virtual void clear ()=0; 11 Counts the number of times a given entry appears in bag. II Input: anEntry The entry to be counted II Returns: The number of times anEntry appears in the bag virtual int getFrequencyof(const ItemType\& anEntry) const =; 11 Tests whether this bag contains a given entry. 11 Input: anEntry The entry to locate II Returns: True if bag contains anEntry, or false otherwise virtual bool contains(const ItemTypes anEntry) const =0; 11 Empties and then f111s a given vector with all entries that 1/ are in this bag. II Returns: A vector containing all the entries in the bag virtual std:tvectoreItemTypes toVector() const =; II Destroys object and frees memory allocated by object. virtual mBagInterface () \{) 1/ end BagInterface endif Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started