DOC PREVIEW
UE CS 215 - CS 215 ­ Fundamentals of Programming

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 215 - Fundamentals of Programming IISpring 2011- Project 330 pointsOut: February 11, 2011Due: February 21, 2011 (Monday)Note that this assignment is worth 50% more than the previous projects. It is also about 50% larger than the previous projects, so it is due in 10 days rather than 7 days. Do not waste the extra days...A 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.Specifications for Document Class Attributes Object Type Namevector of lines vector<string> linesindex of current line size_t currThe Document class stores a document as a vector of lines (i.e., strings that may contain non-newline whitespace). It uses an index, curr, to keep track of the current line that its operations may act upon, similarly to the sequence container covered in Lecture 11 and Homework 6. Unlike the sequence container, there is always a valid current line index unless the document is empty. Minimally, a document might look like the following:02/10/2011 Page 1 of 7"line 1""line 2""line 3"1currlines[0][1][2]Document d;This document consists of the three lines: line 1 line 2 line 3and the current line is "line 2". You may use these attributes somewhat differently than shown, but the data storage must be a vector and the indicator of the current line must be an index into that vector. Adding additional attributes to aid in implementing the Document operations must receive prior approval from the instructor.Operations Default constructor - creates an empty document.● Analysis - no objectsExplicit-value constructor - creates a document from an input stream. Assumes the input stream is open and valid. Each line of the stream is stored as a line of the document. The current line is set to the first line.● Analysis Objects Type Movement Nameinput stream istream received & passed back inIsEmpty - returns true if the document has no lines; false otherwise● Analysis Objects Type Movement Nameboolean result bool returned -----Insert - inserts a line in front of the current line; the inserted line becomes the current line. If the document is empty, the line becomes the first line in the document.● Analysis Objects Type Movement Nameline to insert string received newLineAppend - inserts a line at the end of the document making it the current line. If the document is empty, the line becomes the first line in the document.● Analysis Objects Type Movement Nameline to insert string received newLine02/10/2011 Page 2 of 7Replace - replaces the contents of the current line. If the document is empty, this operation is ignored.● Analysis Objects Type Movement Namereplacement line string received newLineDelete - removes the current line from the document; 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, this operation is ignored.● Analysis - No objectsFind - finds the first line in the document containing the target string (as a substring) and makes it the current line. If no line contains the target string, then the current line remains the same. Returns true if a matching line is found; false otherwise.● Analysis Objects Type Movement Nametarget string string received targetboolean result bool returned -----SetCurrent - sets the current line (index) to the nth line from the beginning of the document with the first line numbered 1. If the document has fewer than n lines or n < 1, the current line remains the same. Returns true when successful; false otherwise.● Analysis Objects Type Movement Nameline number of the new current line int received nboolean result bool returns -----MoveCurrent - moves the current line (index) |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, the current line remains the same. Returns true when successful; false otherwise.● Analysis Objects Type Movement Namenumber of lines to move the current line int received nboolean result bool returned ----02/10/2011 Page 3 of 7WriteLine - writes the current line to an output stream. If the document is empty, this operation is ignored.● Analysis Objects Type Movement Nameoutput stream ostream received & passed back outWriteAll - writes all the lines in the document starting with the first line to an output stream; the current line remains the same.● Analysis Objects Type Movement Nameoutput stream ostream received & passed back outAssignment (20 points) Write the implementation of the Document class. The Document class definition should be put in header file document.h with suitable compilation guards. The implementations of the Document class functions should be put in source file document.cpp. This project must be implemented using an STL vector and an index into this vector. Projects that do not do 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 with the current line set to the first line (if the file is not empty), then allow the user to interactively edit the file by using the following command set. Commands may be entered in upper or lower case. An example run is shown below.Command DescriptionI lineInsert a line in front of the current line making it 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 making the next line the current line, unless the current line is


View Full Document

UE CS 215 - CS 215 ­ Fundamentals of Programming

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
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 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 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?