Assignment 4
Version 1.0 (Fall 2012)
Revised by Peter Liu


Linked Lists of Fields


In this fourth assignment, you are going to add check list and menu functionality to your Field class hierarchy.


Learning Outcome

Upon successful completion of this assignment, you will have demonstrated the abilities

  • to derive one class from another in an inheritance hierarchy,
  • to use inheritance to minimize the duplication of coding in a set of similar classes,
  • to use polymorphism to access the most derived function for an object,
  • to use default parameters to simplify the coding of overloaded functions,
  • to do programming with linked lists.

Specifications

Your fourth assignment adds two classes to the iFrame hierarchy as shown below. 

remaining frame classes

This upgrade includes changes to the checkbox and radio button class files (cswitch.h, cswitch.cpp) and the introduction of two new modules: CCheckList and CMenu

I. Upgrade to Existing Class

A. CSwitch

Upgrade your CSwitch class to handle casting, radio-state resetting, and selection.  Add the following public methods:

  • bool radio() const - returns the radio state of the switch. 
  • void radio(bool) - sets the radio state to the value received. 
  • operator bool() const - returns the selected state of the switch. 
  • operator char*() const - returns the address of the label's data string (cast to a pointer to a char). 
  • bool operator=(bool) - sets the selected state of the current object to the state received and returns that state. 

See the notes on Conversions for the operator bool() and operator char*() methods.

II. New Classes

A. CCheckList

A CCheckList object is a CField object that represents a linked list of checkboxes or radio buttons.  The CCheckList class points to 32 CSwitch objects and includes an unsigned instance variable that keeps track in its individual bits of the checked/unchecked state for each checklist item (each CSwitch object is associated with its own flag).

The CCheckList constructor receives seven values in its parameters (default in parentheses):

  1. const char* - the address of a C-style null-terminated string that contains the format for a checked checklist item
  2. int row - the row position of the checklist relative to the parent frame, if any
  3. int col - the column position of the checklist relative to the parent frame, if any
  4. int width - the width of the checklist
  5. bool radio - the radio status of the checklist
  6. bool bordered - the bordered status of the checklist
  7. const char* border - the address of a C-style null-terminated string describing the field's border (C_BORDER_CHARS)

The constructor passes the row, col, width, bordered, and border values directly to the CField constructor along with the address of the instance variable that holds the selection flags.  Initially, the checklist is empty with no item(s) selected. 

Your design includes a destructor that removes all of the checklist items that have been added to the list.

Your design implements the following public methods (default in parentheses):

  • CCheckList& add(const char*, bool = false) - allocates memory for a new checklist item and adds it to the checklist.  This method passes the received address and checked state to the new item's constructor

  • CCheckList& operator<<(const char*) - adds a checklist item without checking the item

  • CSwitch& operator[](unsigned) - returns a reference to the checklist item at the received index

  • void draw(int = C_FULL_FRAME) - draws the frame for the checklist and draws the items in their checked/unchecked state

  • int edit() -

  • bool editable() const - returns true

  • unsigned getFlags() const - returns a copy of the instance variable that holds the checked state flags for the list

  • void setFlags(unsigned) - resets the instance variable that holds the checked state flags to the value received

  • bool radio() const - returns the radio state of the list

  • void radio(bool) - resets the radio state of the list to the state received

  • int selected() const - returns the index of the currently selected item in the list

  • void selected(int) - resets the currently selected item to the item at the received index

  • const char* selectedText() const - returns the label of the currently selection item

  • const void* pdata() const - returns the address of the data item pointed to by the CField base class part of the current object

  • void set(const void*) - resets the data item pointed to by the CField base class part of the current object

NOTE: You must store your class definition in a new header file named cchecklist.h and your function definitions in a new implementation file named cchecklist.cpp.

B. CMNode

The CMNode class describes the structure of a single menu node.  This class is fully private and only accessible by your CMenu class.  To enable this, grant your CMenu class friend status.

The constructor receives four values in its parameters (default in parentheses):

  1. CMenuItem* - the address of the menu item attached to this node
  2. unsigned - the index of the menu item in CMenu
  3. CMNode* - the address of the previous node
  4. CMNode* - the address of the next node ((CMNode*)0)

The constructor stores the values received in the object's instance variables.  The menu item has its dynamic memory allocated outside this class. 

The destructor deallocates the dynamic memory for the menu item associated with this node. 

C. CMenu

A CMenu object is a CField object that holds a linked list of CMNode objects.  The CMenu class provides support for two types of menu:

  • a drop-down menu,
  • a simple static menu.

The drop-down menu has a button that is always visible.  The menu options of a drop-down menu are hidden unless the user is in the process of selecting an option, in which case the options are visible immediately below the label.  The static menu has no button and always displays its options.  In either case, the options are displayed within a bordered frame. 

Your design includes two constructors: one that receives the address of the C-style null-terminated string that holds the button's label and another without this address. 

The first CMenu constructor, which creates a drop-down menu, receives seven values in its parameters (default in parentheses):

  1. const char* - the address of a C-style null-terminated string that contains the menu's title
  2. const char* - the address of a C-style null-terminated string that contains the format for the menu's items
  3. int - the row position relative to the parent frame, if any
  4. int - the column position relative to the parent frame, if any
  5. int - the width of the menu
  6. int - the height of the menu
  7. const char* - the address of a C-style null-terminated string describing the field's border (C_BORDER_CHARS)

This constructor passes the row, col, width, and height values directly to the CField constructor along with the address of the instance variable that holds the selected index and the border characters for the frame outline.  The row value is one plus the value received to accommodate the button.  This constructor passes the address of the button label's string to the button's constructor and identifies the menu as the button's parent.  Initially, the menu is empty with no item selected. 

The second CMenu constructor, which creates a static menu, receives six values in its parameters (default in parentheses):

  1. const char* - the address of a C-style null-terminated string that contains the format for the menu's items
  2. int - the row position relative to the parent frame, if any
  3. int - the column position relative to the parent frame, if any
  4. int - the width of the menu
  5. int - the height of the menu
  6. const char* - the address of a C-style null-terminated string describing the field's border (C_BORDER_CHARS)

This constructor passes the row, col, width, and height values directly to the CField constructor along with the address of the instance variable that holds the selected index and the border characters for the frame outline.  Initially, the menu is empty with no item selected. 

Your design includes a destructor.  The destructor removes all of the node from dynamic memory.

Your design implements the following public methods (default in parentheses):

  • CMenu& add(const char*, bool = false) - adds a new node that points to the menu item that holds the text stored in the received address and optionally selects the item for the menu

  • CMenu& operator<<(const char*) - adds a menu item that holds the text pointed to by the received address without selecting the item

  • CMenu& operator<<(bool) - selects the last item in the menu

  • void draw(int = C_FULL_FRAME) - for a dropdown menu, draws the button and the menu items if the menu is dropped; for a static menu draws the items

  • int edit() - captures the key press when control is at the option by calling the CField version of this method

  • bool editable() const - returns true

  • int selected() const - returns the selection state

  • void selected(int) - resets the selection state to the state received

  • const char* selectedText() const - returns the selection state

  • const void* pdata() const - returns the address of C-style null-terminated string stored in the menu item associated with the index pointed to by the CField base class part of the current object

  • void set(const void*) - resets the selection state to the state stored at the received address

NOTE: You must store your class definition in a new header file named cmenu.h and your function definitions in a new implementation file named cmenu.cpp.


Test Run and Application

A test program (a4test.cpp) that uses your upgraded library is here.  This program lets your team test its implementation.  Set the TEST_RUN macro to the value that identifies your test : 9 or 10. 

  1. validated line field
  2. switch field
  3. menu item field
  4. text field
  5. check list
  6. menu field

To complete your assignment, prepare an application that uses every element of your CFrame library. 


Submission

Compile and link your upgraded library module with your application in each of the three command-line environments. 

For submission purposes, your solution must compile, link and run without errors in each environment.  Store the three executables in a sub-directory of the trunk of your repository.  Branch the sub-directory to A4.R1.0 under the tags directory of your repository.

Grading

The base mark for an error-free submission with no application is 9/10.  To earn 10/10, your team must submit a useful application without violating the specifications.

As for evaluating team work, each team member must demonstrate that one has contributed significant code base and has fixed the bug(s) in someone else's source code. Each team member must submit a LOG file at the subdirectory to document concisely one's own contributions to the code base.

If your code contains one major or more than one minor logic flaw, your instructor will ask you to fix and resubmit your code, which will attract a 30% penalty.  The late penalty is 20%, so it is better to submit a working version late than to submit a flawed version on time.  Very late assignments and resubmissions will attract a 50% penalty. 

Regardless of how long it takes you to complete this assignment, your team still needs to submit a completed working version in order to pass this subject.







  Designed by Chris Szalwinski   Copying From This Site Last Modified: 12/27/2011 19:55  
Logo