Assignment 6

DUE: Sun May 8, 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 assignment7 you will be writing a "text viewer" using the Big C++ graphics package. The goal will be to be able to read a file in the graphics window. For this assignment(assignment 6)we will be building the foundations that you will need for assignment7. You will implement a TermTextViewer class which displays a file in the terminal. 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

TermTextViewer()
The default Constructor for the TermTextViewer class.
TermTextViewer( const std::string & name_of_file )
Constructor for the TermTextViewer 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 terminal.

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 terminal.
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.

In addition to implementing the class, you will write a main program which tests your class. The main function will attempt 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

When the view method of the TermTextViewer is called, it will display the text of the file in the terminal starting at the beginning of the original file. It will display up to 20 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.

In order to move to the next page of text, the user must hit the return key. If more text is available the user should be made aware by displaying the following text at the bottom of the terminal.

--More--

If more text isn't available, "--More--" should not be displayed. The user should be able to quit viewing the file at any time by typing the character "q" followed by a return. In the event that the file the TermTextViewer is supposed to read from can not be opened. The TermTextViewer should display a message stating the problem and wait for the user to quit the viewer.

Attacking the Problem

Completeing this assignment will presents you with a set of challenges such as:

The best way to figure out these things may not be to try figuring them all out at the same time. It may be to your benefit to write a few programs to figure out how to do these things. For instance you may want to write a program that reads in the contents of a file and writes it to the screen. Once that works, you might try writing it to the screen so that each line is only 48 characters long. Once that works you might try breaking the lines at the end of words as apposed to in the middle of them.

Also, you will not be able to do this assignment without figuring out how to effectively use the string class. In the lab notes there is a link to SGI's documentation of the string class. You may want to do a little bit of googling on you own and figure out which methods you will need to use, as well as how to use them.

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 TermTextViewer 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.
termtextviewer.h
Declaration of the TermTextViewer class. You may not change the public members of this class, although you can add or remove private members as you see fit.
termtextviewer.cpp
Definition of the TermTextViewer 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

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 assn6_sample in the assn6 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 assn6_sample so that it is user executable. You can do this with the command:

chmod u+x assn6_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 20 lines per page.
.5 pts Multiple page support.
.5 pts "q" followed by return exits the viewer.
.5 pts Return moves to next page.
.5 pts "--More--" prompt 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.