CS 153 Data Structures I
Programming Assignment #4
Due: 9/13/01
This programming assignment is designed to reinforce your ability to:
- implement a Bag data structure container
- implement the use of a ListBox
- review the use of Insert, Find, Remove, isFull and isEmpty in the context
of an array of char
NOTE ON THE USE OF PREVIOUS FILES - Don't
You will probably want to use much of the code that you developed for assignment
#3. To do that, follow these suggestions
- Create your new project 4
- Copy/paste the .h and .cpp files from assignment 3 into your new project
4 directory
- From the 'file' view, right click on the ProjectFiles entry and select 'Add
file to project'
- Modify the copied files to meet the new specifications
In order to meet these goals you will keep the user interface from Assignment
#3 with the exception of changing the INPUT edit box to type CString
- an edit box for entering a CString
- an edit box for displaying messages (type CString)
- a button labeled Insert
- a button labeled Find
- a button labeled Remove
- a button labeled Empty?
- a button labeled Full?
- a ListBox
The behavior of your program should be as follows:
- When Button Insert is clicked the CString in the edit box is added to the
'bag' (the char * array) and the contents
of the Bag should be displayed in the ListBox.
- When Button Find is clicked you should search the 'bag' for the null
terminated string that was specified in the edit box and display SUCCESS
or FAILURE in the Message-edit-box
- When Button Remove is clicked you should remove the null
terminated string that was specified in the edit box from the 'bag'.
If it was present, the contents of the Bag should be redisplayed in
the ListBox and REMOVED should be displayed in the Message-edit-box.
If it was not present, NOT FOUND should be displayed in the Message-edit-box.
- When Button Empty? is clicked a message should appear indicating TRUE or
FALSE
- When Button Full? is clicked a message should appear indicating TRUE or
FALSE
Hints for CBag:Insert(CString arg);
- declare m_data to be an array of 10 NTS locations/addresses/pointers
- find the length of arg
- allocate a dynamic null terminated string (NTS) of appropriate length
- strcpy the content of arg into the NTS
- store the location/address/pointer of the NTS into the appropriate m_data[i]
Hints for CBag::Remove(CString arg);
- use strcmp to compare each of the NTSs in MyBag to arg
- if you find one that is equal (i.e., it's location is store in m_data[i])
- move the locations around just like you did with the integers last week