Final Programming Project
Due: Tues, August 4 (in class)
Objective: Upon completion of this program,
you should gain experience with implementing a medium sized software project using
object oriented design principles, using linked lists for object composition,
and working with dynamic memory and pointers.
The code for this assignment should be portable -- for the demo you must
compile and run your code on linprog.cs.fsu.edu.
Task
Your assignment is to create a c++ text editor. The text editor will be comprised of
three components:
- A Page class that manages a page of text stored as a two-dimensional
char array. The page has MAX_VERT lines numbered (0 - (MAX_VERT-1)) and MAX_HORI chars
per line. The Page class will provide several member functions for managing a
page of text, including an Edit() function that takes a single command/line from the
keyboard and implements a change to the page.
- A Document class that manages a linked list of pages and provide functions to
interact with and edit those pages. In addition, the Document class will allow a
document to be saved to a file or loaded from a file.
- A driver file named "textedit.cpp" that manages a single document object and
interacts with the Document based on user input
Here are the header files for the Page Class and the Document Class.
Here is my version of the texteditor executable compiled on linprog. Any questions
of functionality may be answered by working with my version of the text editor. Your text editor should work exactly as
mine does.
Specification
Page Class
Document Class
- void Initialize( ) - Initializes new Document to have a single page. The single page should be
the active page and the Document name should be the empty string "".
- void Destroy( ) - Removes dynamic memory associated with Document. (Hint - do NOT accidentally
use a pointer to deleted memory)
- void Reset( ) - Removes dynamic memory associated with document and initializes the
Document as though is had just been created.
- Document( ) - Default document constructor, initializes new Document object with a single page.
- ~Document( ) -Document destructor, removes dynamic memory associated with Document.
- void NewPage( ) - Dynamically allocates a new blank page to the Document and sets it as the
active page. Updates Document list pointers accordingly (we assume a document always has
atleast one page).
- Page *GetPage( int n ) - Returns a pointer to the n'th page in the Document's linked list of
pages. If page n does not exist, returns NULL.
- bool SetActivePage( int n ) - Sets the n'th page as the active page if possible. Returns
true on success, false on failure.
- void PrintHeader( ) - Prints header for the active page. (PROVIDED FOR YOU!)
- void PrintFooter( ) - Prints footer for the active page. (PROVIDED FOR YOU!)
- void EditActivePage( ) - This function allows the user to edit the active page of the document. The
function will display the active page header, the active page, and the active page footer. The function should
then call the active page's Edit() routine, and implement the command it returns (ex. if Edit() returns PREV_PAGE,
the active page should be changed to the previous page, if one exists). This function loops until the EDIT_DONE
command is received.
- bool Save( ) - This function prompts the user for a file name and if the file can be
be opened, the Document is copied to the file starting with the number of pages, a newline, then
the text of each page. Return true on success, false on failure. The Document name should be changed to
the filename on success.
- bool Load( ) - This function prompts the user for a filename and attempts to open the file.
If unsuccesful, the calling Document should be unchanged and Load() should return false. Otherwise,
the current version of the Document is discarded and a new one is loaded from the file. Bad file input
does not need to be checked. Return true on success. The Document name should be changed to
the filename on success.
TextEdit (driver)
The driver is the simplest part of the assignment as it manages a single Document object. A menu is displayed
to the user and the object is manipulated based on the users choices. The code for displaying the menu is provided
for you. You must only implement a loop that satisfies the choices the user selects. The user may start a new document,
load a document, or exit the program.
Additional Information
- Here are the functions I have provided for you.
- I have provided you with my object files document.o and
textedit.o. This will allow you to compile your page.cpp into
a complete program to test it before you move on to document.cpp. You can also test your document.cpp and page.cpp
with my version of the driver.
- Here is a useful programming for learning how to decode commands
- You should code this project in the order it is presented in the specification section of this page. This will allow
your functions to build on one another.
- Although this project will be graded in class, you MUST still submit it via blackboard before your demo. I will hand
out grading sheets before the due date.
- You need to have a makefile for this assignment.
Submit the following files (using blackboard):
page.cpp
document.cpp
textedit.cpp
Makefile