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

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 00:30
Asecurity policy is a a. set of guidlines b. set of transmission protocols c. written document d. set of rules based on standards and guidelines
Answers: 2
question
Computers and Technology, 24.06.2019 07:50
Write a defining table and then a program that determines if you can sleep in or not. your program should get all its input from your computer’s clock. on all weekdays (monday through friday) that are not holidays, your program should output “get up! ” on all other days (weekends and holidays), your program should output “sleep in.” the three holidays that your program must check for are january 1 (new year’s day), july 4 (u.s. independence day), and december 25 (christmas). you don’t need to include other holidays in your program because most other holidays do not occur on a fixed day each year.
Answers: 1
question
Computers and Technology, 24.06.2019 15:30
What is the total number of time zones that can be configured to show by default in a calendar in outlook 2016?
Answers: 1
question
Computers and Technology, 24.06.2019 19:00
Which of the following "invisible" marks represents an inserted tab?
Answers: 1
You know the right answer?
#include #include "ArrayBag. cpp"using namespace std;int main() {/*ArrayBag bag; srand(time(0));for(...
Questions
question
Mathematics, 25.01.2021 21:10