Assignment 3

DUE: Sun April 17, 11 pm
(10% penalty for late submission, up to 1 day late)

Changes, Errata and Helpful Hints

Any changes to this document, typically due to an error on the part of the author, will be logged here.

Collaboration

Collaboration is strongly ENCOURAGED within a programming team, but the program you submit must still represent YOUR OWN original work. Teams should work on the algorithm together, and help debug/test each others code. However, copying code from ANY outside source (any book, current or past students, past solutions, web sites, etc.) is STRICTLY FORBIDDEN. Copy and Paste from another solution, including the solution of a team mate will incur a stiff penalty.

Problem Definition

For assignment2 you had to write a function which drew a "button" in the drawing area. Once again we will continue on a familiar theme, but this time you will be implementing a "button object" by writing a button class.

As we hope to use the button class later, we will try to give it a robust, yet general set of functionalities. A description of the methods which provide these functionalities follows:

Constructors

Button()
The default constructor shouldn't normally be called. In the default constructor the member variables should be set to relatively benign values.
Button( const Point & ul_corner, const std::string & label )
This constructor should set the button to be shown, and set the member variables to correspond to a button at the given location with the given label.

Accessors

void draw() const
The draw function should draw the button in the drawing area if the button is shown.
bool isClicked( const Point & click ) const
If the Point given as a parameter is within the perimeter of the button, the button has been clicked. However, buttons which are not currently shown can not be clicked.

Mutators

void show()
Make the button shown. If a button is shown it will be drawn in the drawing area when the draw method is called on the button.
void hide()
Make the button hidden. If a button is hidden it will not be drawn in the drawing area when the draw method is called on the button. Also, a hidden button can not be clicked.
void move( const double x_displace, const double y_displace )
Move the button by the specified displacement.
void move_to( const Point & loc )
Move the button to the absolute coordinate given by loc.
void center( const Point &loc )
Center the button on the absolute coordinate given by loc.

Again you will be given the file "global_const.h" which contains constants describing the size of text drawn in the drawing area. You may take the specification of how the button is to be drawn from the Button Specification in assignment2. The declaration of the button class is provided for you. You must write the function definition for the methods of the button class.

You will then write a main ( ccc_win_main ) program which tests your function. The main function will set up the graphic window so the upper left hand corner is at the point ( 0, 0 ) and the lower right hand corner is at the point ( 100, 100 ). It will then draw a button centered in the window with the label of "quit" and another button in the upper right hand corner with a label of "show/hide". If the "show/hide" button is clicked, the shown status of the "quit" button should be toggled. If the "quit" button is clicked, the program should terminate. If any other point in the drawing area is clicked, the "quit" button should be centered on the point where the drawing area was clicked. Any time a click is made in the drawing area, the window should be cleared and all the objects in the drawing area should be redrawn.

In the event that the buttons overlap, and the drawing area is clicked in the region where the two buttons overlap, you should assume that the "show/hide" button is clicked rather than the "quit" button.

Assignment Framework

For this assignment a framwork will be provided for you which includes all of the files that are necessary for you to complete the assignment. The files included in the framework are the following:

main.cpp
Use this file to implement the program which demonstrates the functionality of the Button class.
Makefile
Your makefile must use the options specified in the class coding standard. The first rule in the makefile shall have a target name of "all" and will compile the program with the default executable name of "a.out". Your makefile must also have a rule with a target name of "clean" which removes the executable and any backup files that were generated by your editor.
global_const.h
Constants describing text in the window. You may not edit this file.
button.h
Declaration of the Button class. You may not edit this file.
button.cpp
Definition of the Button class.

You may download the framework here. To uncompress the framework archive you should type:

tar -xzvf <framework_file>

where <framework_file> is the name of the file that you downloaded.

What To Turn In

Your code must compile on the school's linux system, using the flags specified in the class coding standards. You must provide a makefile with the targets "all" and "clean" so the grader can compile you assignment. Submit your work (the source file(s) and Makefile ONLY) electronically to the correct folder on the cs secure server. Don't forget to include the header template at the top of each file that you submit.

For this assignment you will turn in the following files:

The files should be inside a folder named assn3. Each file that you have written should conform to the class coding standard. This includes but is not limited to:

Example

You can soon download a sample program by right-clicking and save-as here. You will probably need to change the permissions on the file so that it is user executable. You can do this with the command:

chmod u+x assn3_sample

Grading Rubric (10 pts total)

If your program does not compile, it will not be graded. Compile your code often. Only write a small portion of code before checking that it still compiles. This way when you get a syntax error, you can be fairly certain the error is in the part you just wrote.

The points for this assignment will be distributed as follows:

Points Feature Description
2 pts Program compiles
3 pts Adherence to the class coding standard
-- ( .5 pts ) Program does not use global variables or objects
-- ( .5 pts ) Good variable and function names
-- ( .5 pts ) Proper indentation and spacing
-- ( .5 pts ) Good comments ( including header and function comments )
-- ( .5 pts ) No line wraps
-- ( .5 pts ) Other miscellaneous parts of the standard.
1 pts Program draws both buttons.
1 pts Hide/show button works properly.
1 pts Program exits when the "quit" button is clicked.
2 pts "Quit" button is centered on a point in the drawing area when the drawing area is clicked.