CS 153 Data Structures I
Programming Assignment #3
Due: 9/5/01
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
-
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?
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' (the int 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 integer
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 integer 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 organizing your code:
Your program should be organized with Bag.h (a new file that you have created)
containing the Bag class declaration and Bag.cpp (a new file that you have created)
containing the Bag functions definitions: The following functions should
be public
-
Bag();
// The constructor. Should initialize m_size
-
void Insert(int)
-
bool Find(int)
-
bool Remove(int)
-
bool isEmpty()
-
bool isFull()
-
void Display(CListBox &)
The following data should be private:
-
int m_data[10];
-
int m_size;
The OnBUTTONxx functions should of course be located in the ...Dlg class
Your OnBUTTON_Insert might look like:
void CProg3Dlg::OnBUTTON_Insert()
{
UpdateData(TRUE);
my_bag.Insert(m_Input); // my_bag is a member variable of your ...Dlg class
// m_Input is the value from you Edit Box
my_bag.Display(m_OutputListing); // Discussed below
UpdateData(FALSE);
}
The Display(..) function will get called from both OnButtonInsert and
OnButtonRemove. It must pass the CListBox (since the ListBox belongs
to the ...Dlg class and the Display(...) function is a member of the Bag
class. The Display function might look like the following.
void Bag::Display(CListBox & listing )
{
char temp[20];
// used to pass a value to the ListBox
listing.ResetContent();
for( int i = 0; i < m_size; ++i )
{
itoa(m_data[i], temp,10);
listing.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 Display function above shows you how to 'put stuff into the ListBox'