The following is part of the program which has an array list ADT, named a Bag. T
ID: 3736614 • Letter: T
Question
The following is part of the program which has an array list ADT, named a Bag. The program has the following header to def ne the class: / header #ifndef-BAG- #define-BAG- typedef int bag-type; class Bag private: int count; // members in bag static const int MAX_SIZE 20; bag type data[MAX_SIZE]: /I data store up to 20 members public: Bag Constructor bool insert (bag_type); // Put a member in the bag bool remove (bag type); I/ remove a member from the bag int size I/ number of members in bag void clear); // remove all members from bag bool inbag(bag-type); // s a member in the bag? int howmany (bag type); // how many member in bag ); #endif The main function is used as a driver to demonstrate the Bag class like this //main #include #include #include "bag"h" using namespace std; int main() Bag b; bag_type value; coutExplanation / Answer
Output:
Bag
4 elements in the bag
2 6's in the bag
3 elements in the bag
1 fours
0 fives
Explanation:
first we inserted 4 elements in bag 5,6,2,6. so size of bag at this time size of bag is 4
we can see we have inserted 2 6's in bag.
Now we removed 2 from bag so size of bag at this time will be 3
now we have cleared bag that means again bag is empty
We have inserted two elements 4,8 again in bag
Now in bag only 1 fours and 0 fives
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.