Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,084 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,538 people online right now. Registration is fast and FREE... Join Now!




A bag Object

 
Reply to this topicStart new topic

A bag Object

dutchharp
21 Apr, 2008 - 02:08 PM
Post #1

New D.I.C Head
*

Joined: 21 Apr, 2008
Posts: 2


My Contributions
This is the instruction I was given from my instructor;
Write the bag.cpp file, given bag.h and test11a.cpp, main program

Here is the total instructions from the text book;
Write a menu-driven program that allows the user to add as many elements as desired and to see the collection of elements at any time.

This is what I have so far

#include <iostream>
#include <string>
using namespace std;
typedef string BAG_ELEMENT_TYPE;
#include "bag.h";

int main()
bag();
// post: Size of this bag is 0.
// Initial capacity == DEFAULT_INITIAL_BAG_CAPACITY

bag(int initCapacity);
// pre: initCapacity >= 1
// post: size of this bag is bag to 0 with the capacity
// to store initCapacity BAG_ELEMENT_TYPE objects



//--modifiers
void add(BAG_ELEMENT_TYPE newElement);
// post: Add newElement to this bag and increase
// the size of this bag object increased by +1.

// Note: If capacity < size, the bag doubles it capacity

bool remove(BAG_ELEMENT_TYPE removalCandidate);
// post: If found, removalCandidate is removed from this bag.

void sort ();
// post: sort in ascending order

//--accessors
int capacity() const;
// post: return the maximum number of elements that could be stored in this bag

int size() const;
// post: return the number of elements that are currently in this bag
// the number of objects added but not removed.

bool isEmpty () const;
// post: Returns true if there are zero items in the bag.
// Returns false if there is one more added elements

//--iterator functions

void first() const;
// post: my_index points to the first item,
// or if the bag is empty, isDone would now return true
// Make sure there is at least one item in the bag
//if my_size greater than 0

//Because the first() and next() are const, you need to use a
// pointer to change the value of my_index so that the const
// method will not complain. This is the only situation this
// trick should be used to subvert the meaning of const
//((bag*)this)->my_index = 0;

void next() const;
// post: my_index points to the next item, or isDone now returns true
// Cast away const so this appears to not modify the object
// This is the only situation this trick should be used to subvert the meaning of const
// ((bag*)this)->my_index++;

bool isDone() const;
// post: Returns true if the collection has been traversed

BAG_ELEMENT_TYPE currentItem() const;
// pre: ! isDone && my_size > 0
// post: Returns the item pointed to by the my_index
int occurencesOf(BAG_ELEMENT_TYPE matchValue);
User is offlineProfile CardPM
+Quote Post

corliss
RE: A Bag Object
21 Apr, 2008 - 04:05 PM
Post #2

D.I.C Head
Group Icon

Joined: 25 Oct, 2006
Posts: 119



Thanked: 1 times
Dream Kudos: 50
My Contributions
Foreals. please use the code tags. and please include to all your source files.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 07:58PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month