Assignment 2

DUE: Sun April 10, 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.

Problem Definition

Last week you got practice drawing shapes in the drawing area. For this assignment we're going to continue with this theme, except this time we will be writing text to the drawing area in conjunction with the drawing of shapes. What we will draw this week is a rectangle with text written inside of it. You might recognize this kind of object as a "button".

For this assignment you will write a function which takes as parameters the upper left corner of a button and a string representing the "label" of the button. The function will write the label to the screen with a rectangle drawn around it. The upper left hand corner of the rectangle will be the point sent to the function as a parameter. The declaration of the function is as follows:

//! \brief Draw a button in the drawing window at the specified
//!        location with the specified label.
//! \param upper_left The upper left hand corner of the button.
//! \param label The text which appears inside the button.
//! \return Void.
void draw_button( const Point & upper_left, const std::string label );

More information about how the button is drawn is given below in the Button Specification section.

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 prompt the user to click on a point in the window where they want the button to be drawn. After a point is entered by the user, the program will prompt the user to enter a string that should be the label of the button. You do not have to be able to handle multiple word strings, a single word is sufficient.

Once the position and label of the button have been obtained from the user, the screen should be cleared and the new button should be displayed in the graphic window by calling the draw_button function. Your program should continue prompting the user for a new location and a label for the button, and drawing the button in the graphic window until the user types "quit" as the button label.

When the user types "quit" as the button label, the program will draw the button with "quit" as its label and terminate. It is OK if the graphic window remains displayed on the computer screen.

Button Specification

When a Message object is displayed in the graphic window it is always the same size regardless of the coordinate system that has been set up with the cwin.coord( ... ) function. This makes it quite difficult to draw objects and text together in a way that is independent of the coordinate system being used. For this reason, amoung others, in every remaining assignment which uses the graphic window we will fix the graphic windows upper left hand corner at the point ( 0, 0 ) and its lower right hand corner at the point ( 100, 100 ).

Since we are permanently setting the size of the graphic window, we can define some constants which represent how wide and how tall a letter is when it is written in the graphic window. These constants are defined in the file global_const.h which is being provided to you. The constants defined in global_const.h that you will be interested in for this assignment are:

WINDOW_WIDTH
The width of the graphic window.
WINDOW_HEIGHT
The height of the graphic window.
UPPER_LEFT
The upper left coordinate of the graphic window.
LOWER_RIGHT
The lower right coordinate of the graphic window.
LETTER_WIDTH
The width of a letter in the graphic window.
LETTER_HEIGHT
The height of a letter in the graphic window.

To use these constants you simply need to sharp include "global_const.h" at the top of your file.

Since we know the width and height of an individial letter, we can draw the border of the button so that the label is completely contained within the border regardless of the length of the label. When the program draws the rectangle that is the border of the button, the rectangle should be a total of 1 LETTER_WIDTH wider than the label, and 1 LETTER_HEIGHTs higher than the label. The label should be centered in the rectangle. Placing the upper left hand conter of the label half a LETTER_WIDTH to the right, and a quarter of a LETTER_HEIGHT lower than the upper left hand corner of the border of the button centers the label quite nicely.

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 draw_button( ... ) function and your main function.
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. You should always "make clean" before turning in your assignment.
global_const.h
This file contains the constants mentioned in the Button Specification section of this document. You do not need to change or add anything to this file.

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 assn2 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 assn2. Each file that you have written should conform to the class coding standards. This includes but is not limited to:

Example

You may 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 assn2_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.
2 pts Program draws both the label and the border of the button.
2 pts Program places the button in the proper place and adheres to the Button Specification.
1 pts Program prompts the user for input correctly and exits on an input of "quit".