DUE: Sun May 8, 11 pm
(10% penalty for late submission, up to 1 day late)
Any changes to this document, typically due to an error on the part of the author, will be logged here.
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.
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.
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.
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.
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.
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.
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:
You may download the framework here. To uncompress the framework archive you should type:
where <framework_file> is the name of the file that you downloaded.
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:
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:
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. |