Today we will take a look at our first ADT, how to define an interface for it in C++, and discuss possible implementations. Along the way we will get an introduction to CMake and testing using Catch.
A Bag holds a finite number of objects of the same type, not necessarily distinct, with no particular ordering. It supports the following:
construct()
construct an empty bag
destroy()
destroy the bag and any contents
add( Item )
add an Item
to the bag, returns true on success, else false
remove( Item )
remove a single instance of Item
from the bag, returns true on success, else false
isEmpty()
returns true if the bag has no contents, else false
getCurrentSize()
returns the number of items in the bag as an integer
clear()
removes all items in the bag
getFrequencyOf( Item )
the number of times item appears in the bag
contains( Item )
returns true if at least one Item is in the bag, else false
Consider a simplified version of the Bag ADT (without toVector).
bag.hpp
.bag.hpp
via Canvas at the Assignment "Exercise for Meeting 2".Requirements: