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

Info icon This 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
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; 3. Write a class VectorJar which implements all functions listed in the class Jar . This representation defines a jar as a vector that can be automatically expanded dynamically as it is necessary, using C++ class vector .
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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern