2. Rules
❏ Share your screen while you work
❏ You can use the web
❏ You can copy code snippets from the web
❏ You can use anything from the standard library
❏ You may use C++20 (or below)
2
3. Notes
❏ Be creative, but more important, be on time!
❏ You will get a link to these slides + some bootstrap code
3
5. NumCollection c1("-17, -10--5, 20-25, 50");
assert(c1.contains(-10));
assert(!c1.contains(-3));
NumCollection c2("-1000000-5, 1000000");
assert(c2.contains(1000000));
assert(!c2.contains(6));
NumCollection c3("0-5, 10-15, 20, 30-35, 40"); // it can be a much longer sequence
assert(c3.contains(34));
assert(!c3.contains(36));
// limits:
// min = std::numeric_limits<long>::lowest()
// max = std::numeric_limits<long>::max()
5
6. NumCollection - Mandatory Requirements
❏ Constructor to support above use cases
❏ A contains(long) function - getting a long and returning bool
Assumptions:
❏ You can assume that the input to NumCollection is sorted and
without repetitions (each number may appear only once)
❏ You can throw an exception on bad input
6
7. Design Considerations
❏ Think of both runtime and memory efficiency
❏ You may want to handle different inputs differently
e.g:
"10-15, 20-25, 30-35, 40, 43, 45, 47, 50, 52, 55, 57, 59-60"
vs.
"-1000000-5, 1000000"
7
8. Extra Bonuses (pick any or none)
❏ Implement proper tests (e.g. with gtest, catch2 or any other)
❏ Support unsorted inputs and/or repetitions of numbers in the input
❏ Support for add function(s) - thus making NumCollection mutable
❏ Add iterator support for iterating over all contained elements
❏ Add a contains(Predicate) function - returning bool
❏ Add a findAll(Predicate) function - returning NumCollection
❏ Add an intersect(NumCollection) function - returning NumCollection
❏ Support for compile time processing (if possible!)
8
9. Code Bootstrap
You may want to use the sequence parser implemented here:
http://coliru.stacked-crooked.com/a/7b5cab5a64742cad
Note:
You may improve the parsing algorithm if you want.
But this shouldn’t be your first task! Or a task at all.
9