Assignment 7

DUE: Sun May 15, 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 this assignment you will be writing a "text viewer" using the Big C++ graphics package. The goal is to be able to read a file in the graphics window. You will implement a TextViewer class which displays a file in the graphic window. The interface of the class is described below. You are not allowed to change the public interface. However, you may do whatever you wish for the private interface. The private functions shown here are merely suggestions; you can use them, or make up your own.

Public Members

TextViewer()
The default Constructor for the TextViewer class.
TextViewer( const std::string & name_of_file )
Constructor for the TextViewer class. name_of_file is the name of the file to view.
void setFile( const std::string & name_of_file )
Set the name of the file to view.
void view()
View the file in the graphic window.

Private Members ( suggested )

void readTextFromFile()
Read the text from the file and store it in a string.
void showNextPage()
Display the next page of the text in the graphic window.
bool allTextDisplayed()
Test whether the entire contents of the file has been displayed.

Private Data ( suggested )

std::string file_name
The name of the file.
std::string text
The text from the file.
unsigned int cur_text_index
The current index into the text.
Button next
A button for getting the next page.
Button done
A button to stop viewing the text.

In addition to implementing the class, you will 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 attempts to sequentially open three files for viewing. The first file is act 1, scene 1 of Hamlet. The second file is the Declaration of Independence. The third file should not exist; this will test whether the class operates correctly when it can't open a file. These text files are provided in the framework.

Behavior of the TermTextViewer

The TextViewer will make the assumption that the graphic window is set up so that the upper left hand corner is at the point ( 0, 0 ) and the lower right hand corner is at the point ( 100, 100 ). When the view method of the TextViewer is called; it will display the text of the file in the graphic window starting at the beginning of the original file. It will display up to 30 lines of text at a time for the user to read. Each line will be no more than 48 characters long. A line should not break in the middle of a word unless the word is longer than 48 characters. Also, return characters from the original file should be preserved. The displayed text should take up no more that 80 percent of the vertical area of the graphic window. This will allow for the top 5 percent of the window to be blank, and the bottom 15 percent of the window will be left for buttons. The constants declared in global_const.h are set up to adhere to these restrictions.

Two buttons can be displayed by the TextViewer. The "Done" button will always be displayed in the bottom of the window. If the user clicks the "Done" button the TextViewer will stop displaying the contents of the file. There will also be a "Next" button that will move to the next page of the text. If all of the text has been displayed, the "Next" button should be hidden so that the user is aware that the end of the file has been reached.
In the event that the file the TextViewer is supposed to read from can not be opened. The TextViewer should display a message stating the problem and wait for the user to click the "Done" 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 TextViewer 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.
clickable.h
Declaration of the Clickable class. You may not edit this file.
clickable.solution
Object code for the clickable class. You may use this if you want, or use your own clickable class.
button.h
Declaration of the Button class. You may not edit this file.
button.solution
Object code for the button class. You may use this if you want, or use your own button class.
textviewer.h
Declaration of the TextViewer class. You may not change the public members of this class, although you can add or remove private members as you see fit.
textviewer.cpp
Definition of the TextViewer class.
Doxyfile
A configuration file for the doxygen program. If you're interested, type "doxygen Doxyfile" at the command prompt. Then, open the file "./docs/html/index.html" in your favorite browser and see what all this funny commenting stuff is about. However, please delete any documentation that you generate before turning in your assignment.

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

Submit your work 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:

Example

You can download a sample program right-clicking and save as here. Place the file assn7_sample in the assn7 folder that came with the framework in order for it to be able to access the text files. You will probably need to change the permissions on assn7_sample so that it is user executable. You can do this with the command:

chmod u+x assn7_sample

Grading Rubric (10 pts total)

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( And files represent an attempt at completing the assignment )
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.
.5 pts Lines are 48 characters or less.
.5 pts Lines do not break in the middle of a word.
.5 pts Return characters are preserved.
.5 pts 30 lines per page.
.5 pts Multiple page support.
.5 pts Done button exits the viewer.
.5 pts Next button moves to next page.
.5 pts Next button is not shown on last page.
.5 pts Error message is given for non-openable file.
.5 pts Main program attempts to display the three files given in the framework.