T03_CC - Tutorial 3 COMP152 Spring 2010 Container Classes...

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

View Full Document Right Arrow Icon
Container Classes M3 Tutorial 3 COMP152 Spring 2010
Background image of page 1

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

View Full DocumentRight Arrow Icon
Container Classes A container class is a data type that is capable of holding a collection of items In C++, container classes can be implemented as a class, along with member functions to add, remove, and examine items 2 COMP152
Background image of page 2
Bags COMP152 3 For the first example, think about a bag Inside the bag are some numbers When you first begin to use a bag, the bag will be empty We count on this to be the initial state of any bag that we use This bag is empty
Background image of page 3

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

View Full DocumentRight Arrow Icon
Inserting Numbers into a Bag COMP152 4 Numbers may be inserted into a bag The bag can hold many numbers We can even insert the same number more than once I am putting the number 4 into the bag The 4 is in the bag
Background image of page 4
Examining a Bag COMP152 5 We may ask about the contents of the bag. Have you got any 4’s? Yes, I have two of them
Background image of page 5

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

View Full DocumentRight Arrow Icon
Removing a Number from a Bag COMP152 6 We may remove a number from a bag But we remove only one number at a time This 4 is out of here One 4 is gone but the other 4 remains
Background image of page 6
How Many Numbers COMP152 7 Another operation is to determine how many numbers are in a
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

T03_CC - Tutorial 3 COMP152 Spring 2010 Container Classes...

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

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