CS 153 Data Structures I
Programming Assignment #4
Due: 9/14/00
This programming assignment is designed to:
-
implement a Bag data structure container
-
introduce the use of a ListBox
-
review the use of Insert, Find, Remove, isFull and isEmpty in the context
of an array
In order to meet these goals you must create a VC++ GUI that contains the
following items:
-
an edit box for entering an integer
-
a button labeled Insert
-
a button labeled Find
-
a button labeled Remove
-
a button labeled Empty?
-
a button labeled Full?
Plus the following additional window:
The behavior of your program should be as follows:
-
When Button Insert is clicked the integer in the edit box is added to the
'bag' and the contents of the Bag should be displayed in the ListBox.
-
When Button Find is clicked you should search the 'bag' for the integer
that was specified in the edit box and display SUCCESS or FAILURE
-
When Button Remove is clicked you should remove the integer that was specified
in the edit box from the 'bag' if it is present and the contents of the
Bag should be redisplayed in the ListBox.
-
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 organizing your code:
Your program should be organized with Bag.h containing the Bag class
declaration and Bag.cpp containing the Bag functions Insert(), Find(),
and Remove(), isEmpty() and isFull(). The OnBUTTONxx functions should
of course be located in the ...Dlg class
Your OnBUTTONInsert might look like:
void CProg3Dlg::OnBUTTONInsert()
{
UpdateData(TRUE);
m_bag.Insert(m_Input); //m_bag
is a member variable of your ...Dlg class
//m_Input is the value from you Edit Box
DisplayBag(m_bag);
// Discussed below
UpdateData(FALSE);
}
Add a function to ...Dlg named DisplayBag() which might
look like the following. Notice that we are doing something a little
'bad' here. The DisplayBag function is a member of the ...Dlg class,
but we have it accessing the PRIVATE data (m_Data and m_CurSize) of a CBag
object. This is normally not a very good idea. There are ways
to avoid it. You will study some of those ways soon. For now,
if you tell CBag that he/she has a
friend class CProg4Dlg;
this will give a member function in the ...Dlg class full access rights
to the private data of a CBag object
void ...Dlg::DisplayBag(CBag a_Bag)
{
char temp[20];
// used to pass a value to the ListBox
m_YourListBox.ResetContent();
for( int i = 0; i < m_CurSize; ++i )
{
itoa(a_bag.m_Data[i],
temp,10);
m_YourListBox.AddString(temp);
}
}
Setting up the ListBox
-
Drag a ListBox to your dialog window
-
Use properties to Name it and TURN OFF THE SORTED OPTION
-
Use the class wizard to assign a member variable name (m_OutputListing)
to it like you did with the edit box, but the category must be CONTROL
-
The DisplayBag function above shows you how to 'put stuff into the ListBox'