UE CS 215 - CS 215 ­ Fundamentals of Programming II

Unformatted text preview:

CS 215 - Fundamentals of Programming IIFall 2008 - Project 630 pointsOut: November 5, 2008Due: November 19, 2008A line editor is a text editor that operates on lines of a textfile. A line editor manipulates text one line at a time. The editor keeps track of a "current line" at all times, and the commands of the editor are performed relative to this current line. In the past, this type of editor was necessary for printing terminals and dumb video terminals where one could not move around on a screen. Now such editors are used in batch mode where editing commands are read from a file and applied to a target file. For example, source code patches often are distributed this way.Your assignment is to write a Document class (specification given below) that supports line editing of a textfile and to write a (main) program that allows a user to interactively edit a textfile.Dnode<T> structure This project assumes the Dnode<T> structure definition of Chapter 9.5 of the textbook (pages 463-464) for doubly-linked nodes as used in lecture. Since it is a template, the definition should be placed outside and before the Document class definition in the document.h header file. Specifications for Document Class Note: this is not a template class, though it does use the Dnode structure template from the textbook. Attributes Object Type Namepointer to list of linesDnode<string>*frontpointer to current lineDnode<string>*currThe Document class stores a document as a doubly-linked list of lines (strings) with front pointing to the (front of the) list. It uses a pointer, curr, to keep track of the current line that its operations may act upon. Minimally, a document might look like the following:This document consists of the three lines: line 1 line 211/04/08 1 of 6"line 1" "line 2" "line 3"frontcurrDocument doc;line 3and the current line is "line 2". You may want to add other attributes or special nodes to aid in implementing the Document operations.Operations Default constructor - creates an empty document.● Analysis - no objectsCopy constructor - creates a copy of the original Document. Note this includes setting the current line to the equivalent line.● Analysis Objects Type Kind Movement Nameoriginal document Document variable received originalDestructor - deletes a Document's nodes● Analysis - no objects operator= - assignment operator, make this Document the same as the original Document. Note this includes setting the current line to the equivalent line. Returns a reference to this object.● Analysis Objects Type Kind Movement Nameoriginal document Document variable received originalthis document Document & variable returned *thisInsert - inserts a line in front of the current line; the current line remains the same. If the document is empty, then inserts the line as the first one in the document and makes it the current line.● Analysis Objects Type Kind Movement Nameline to insert string variable received lineAppend - inserts a line at the end of the document making it the current line.● Analysis Objects Type Kind Movement Nameline to insert string variable received line11/04/08 2 of 6Replace - replaces the current line; this line becomes the current line.● Analysis Objects Type Kind Movement Namereplacement line string variable received lineDelete - deletes the line at the current position; the current line becomes the next line after the deleted line unless the last line is deleted, then the last line becomes the current line. If the document is empty, throws a RangeError exception.● Analysis - No objectsFind - finds the first line in the document containing the target string and makes it the current line. If no line contains the target string, then throw a NotFoundError exception, and the current line remains the same.● Analysis Objects Type Kind Movement Nametarget string string variable received targetSetCurrent - sets the current line to the nth line from the top of the document with the first line numbered 1. If the document has fewer than n lines or n < 1, throws a RangeError exception and the current line remains the same.● Analysis Objects Type Kind Movement Nameline number of the new current line int variable received nMoveCurrent - moves the current line n places. If n > 0, move in the forward direction (toward the end). If n < 0, move in the backward direction (toward the beginning). If there are fewer than n lines in the appropriate direction, throws a RangeError exception and the current line remains the same.● Analysis Objects Type Kind Movement Namenumber of lines to move the current line int variable received nWriteLine - writes the current line in the document to an output stream. If the document is empty, throws a RangeError exception.● Analysis Objects Type Kind Movement Nameoutput stream ostream variable received & passed back out11/04/08 3 of 6WriteAll - writes all the lines in the document to an output stream; the current line remains the same.● Analysis Objects Type Kind Movement Nameoutput stream ostream variable received & passed back outAssignment (20 points) Write the implementation of the Document class. The Dnode structure definition and the Document class definition should be put in header file document.h with suitable compilation guards (the Dnode structure first, then the Document class). The implementations of the Document class functions should be put in source file document.cpp. This project must be implemented using a doubly-linked list. Projects that do not so will be returned for resubmission with late penalties. (10 points) Write a (main) program in file editor.cpp that has one command-line argument, the name of a textfile to edit. The program should construct a Document object using the given textfile, set the current line to the first line of the file (if the file is not empty), then allow the user to interactively edit the file by using the following command set. An example run is shown below.Command DescriptionI lineInsert a line in front of the current line. If the document is empty, this line becomes the current line.A lineAppend a line to end of the document making it the current line.R lineReplace the current line. If the document is empty, an error message is displayed.DDelete the current line. The next line becomes the current line unless the last line is deleted, then the current line becomes the last line. If the document is empty, an error message is displayed.F targetFind the


View Full Document

UE CS 215 - CS 215 ­ Fundamentals of Programming II

Documents in this Course
Lecture 4

Lecture 4

14 pages

Lecture 5

Lecture 5

18 pages

Lecture 6

Lecture 6

17 pages

Lecture 7

Lecture 7

28 pages

Lecture 1

Lecture 1

16 pages

Lecture 5

Lecture 5

15 pages

Lecture 7

Lecture 7

28 pages

Load more
Download CS 215 ­ Fundamentals of Programming II
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 215 ­ Fundamentals of Programming II and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 215 ­ Fundamentals of Programming II 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?