F print a marble as a pair of its color and size 2

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
(f) Print a marble as a pair of its color and size. 2. Write an abstract class Jar for the marble jar which uses the class Marble . Basic operations on Jar objects: add a new marble m to the jar virtual void add(const Marble& m)=0; check if a given marble m is in the jar: return true if it is there; false otherwise virtual bool is_in_jar(const Marble& m) const =0; remove a given marble m from the jar virtual void remove(const Marble& m)=0; It throws an exception if the given marble is not in the jar. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
remove and return the marble from the jar (it is not important which one) virtual Marble remove_any()=0; It throws an exception if the jar is empty. make the jar empty virtual void clear()=0; return the number of marbles in the jar virtual int marble_number() const =0; return the number of marbles of the same size in the jar virtual int marble_nsize(Marble::Size s) const =0; return the number of marbles of the same color in the jar virtual int marble_ncolor(Marble::Color c) const =0; check if the jar is empty: return true if it is empty; false otherwise virtual bool is_empty() const =0; a merge operation that combines the contents of two jars into a third jar (the contents of jar1 and jar2 are not changed). It behaves like a set, which mean no duplicate is allowed. virtual void merge(const Jar& jar1, const Jar& jar2)=0; an intersection operation that creates a jar of those objects that occur in both of two jars (the contents of jar1 and jar2 are not changed). It behaves like a set, which mean no duplicate is allowed. virtual void intersect(const Jar& jar1, const Jar& jar2)=0; a difference operation that creates a jar of those marbles that occur in the first jar but not in the second one (the contents of jar1 and jar2 are not changed). It behaves like a set, which mean no duplicate is allowed. virtual void difference(const Jar& jar1, const Jar& jar2)=0;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 3

f Print a marble as a pair of its color and size 2 Write an...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online