subject

#include #include "ArrayBag. cpp"using namespace std;int main() {/*ArrayBag bag; srand(time(0));for(int i = 0; i<10; i++)bag. add((double)rand()/RAND_MAX * 100); bag. displayBag(); cout<<"There are "< shoppingBag;shoppingBag. add("shirt");shoppingBag. add("jeans");shoppingBag. add("skirts");shoppingBag. add("shorts");shoppingBag. add("pants");shoppingBag. displayBag();shoppingBag. remove("skirts");shoppingBag. displayBag();vector shoppingVector = shoppingBag. toVector();for(int i = 0 ; i < shoppingVector. size(); i++){cout<using namespace std;const int DEFAULT_CAPACITY = 20;template class ArrayBag{private:T items[DEFAULT_CAPACITY];int numOfItems;/*return the index of the specified item.*/int getIndexOf(const T& item);public:ArrayBag();/*Report the current number of items in the bag. Input: noneoutput: the current number of items in the bag.*/int getCurrentSize();/*Check if the bag is empty or not. Input: noneoutput: return true if the bag is empyt, false otherwise.*/bool isEmpty();/*Add a new item to the bagInput: the new item to added. output: return true if the item is successfully added.*/bool add(const T& newItem);/*remove any item from the bag.*/bool remove();/* remove the first occurance of the specified item from the baginput: Item to be removeoutput: return true if the item is successfully removed.*/bool remove(const T& item);void clear();int getFrequnecyOf(const T& item) const;bool contains(const T& item) const;void displayBag();vector toVector();};#endif ArrayBag. cpp#include "ArrayBag. h"#include using namespace std;//constructortemplate ArrayBag::ArrayBag(){ numOfItems = 0;}/*Report the current number of items in the bag. Input: noneoutput: the current number of items in the bag.*/template int ArrayBag::getCurrentSize(){return numOfItems;}/*Check if the bag is empty or not. Input: noneoutput: return true if the bag is empyt, false otherwise.*/template bool ArrayBag::isEmpty(){return numOfItems == 0;}/*Add a new item to the bagInput: the new item to added. output: return true if the item is successfully added. Since the items in bag doesn't have any particular order, we can always add a new item to end end of the array.*/template bool ArrayBag::add(const T& newItem){//TODOif(numOfItems < DEFAULT_CAPACITY){items[numOfItems] = newItem;numOfItems++;return true;}else{cout<<"No more room to add the new item. "<bool ArrayBag::remove(){if(!isEmpty()){ numOfItems--;return true;}else{cout<<"Nothing can be removed from an empty bag."<bool ArrayBag::remove(const T& item){//1. search for the item// 2. if it is located, remove the item by shifting all elements after the item to the left by 1.// or replace the item by the last element. a//3. decrement the size by 1.if(isEmpty()){cout<<"It's an empty bag. Nothing can be removed."<void ArrayBag::clear(){numOfItems = 0;}template int ArrayBag::getFrequnecyOf(const T& item) const { int cnt = 0;for(int i = 0; ibool ArrayBag::contains(const T& item)const {/*for(int i = 0; ivoid ArrayBag::displayBag(){for(int i = 0; iint ArrayBag::getIndexOf(const T& item){for(int i = 0; ivector ArrayBag::toVector(){vector bagVector;for(int i = 0; i

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 21:50, Trinhphuongtran
Description: write function lastfirst() that takes one argument—a list of strings of the format "lastname, firstname" —and returns a list consisting of two lists: (a) a list of all the last names (b) a list of all the first names
Answers: 2
image
Computers and Technology, 25.06.2019 10:40, camidevecchis15
If you're using the paintbrush tool and want to change the color of the paint being used what should you change
Answers: 1
image
Computers and Technology, 25.06.2019 19:50, brutalgitaffe
What is the leading use of computers
Answers: 3
image
Computers and Technology, 25.06.2019 21:30, alyxkellar06
Hallo! was ist die hauptstadt von northdakote wirklich schätzen, wenn jemand gefragt
Answers: 2
You know the right answer?
#include #include "ArrayBag. cpp"using namespace std;int main() {/*ArrayBag bag; srand(time(0));for(...

Questions in other subjects:

Konu
English, 20.01.2021 03:40
Konu
Mathematics, 20.01.2021 03:40
Konu
English, 20.01.2021 03:40
Konu
Mathematics, 20.01.2021 03:40