Computers and Technology

#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

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:20, ptrlvn01
This problem has been solved! see the answeran evil king has a cellar containing n bottles of expensive wine, and his guards have just caught a spy trying to poison the king’s wine. fortunately, the guards caught the spy after he succeeded in poisoning only one bottle. unfortunately, they don’t know which one. to make matters worse, the poison the spy used was very deadly; just one drop diluted even a billion to one will still kill someone. even so, the poison works slowly; it takes a full month for the person to die. design a scheme that allows the evil king to determine exactly which one of his wine bottles was poisoned in just one month’s time while expending at most o(logn) of his taste testers. you are not allowed to use n testers, one for each bottle, and see which one tester dies after 30 days.(no pseudocode needed. just answer in words, how many testers you use, how you use them and why you correctly identify the poisoned bottle in 30 days)
Answers: 2
image
Computers and Technology, 22.06.2019 00:00, amyeileen
11. is the ability to understand how another person is feeling. a. authority b. sympathy c. empathy d. taking a stand
Answers: 1
image
Computers and Technology, 23.06.2019 22:00, bb1593
Jackson, who works in the finance department of a company, is holding a seminar for other employees on how to file taxes. only three employees sign up to attend the seminar. which device can he use to share his presentation with a group of three employees?
Answers: 1
image
Computers and Technology, 24.06.2019 23:50, fish64
What is your fav video game currently: a) roblox b) fortnite c) apex legends d) pubg
Answers: 2
Do you know the correct answer?
#include #include "ArrayBag. cpp"using namespace std;int main() {/*ArrayBag bag; srand(time(0));for(...

Questions in other subjects:

Konu
Social Studies, 12.01.2020 23:31