Question: CS 5160 Programming Assignment 3 Linked Lists In this programming assignment you will implement a rudimentary line-oriented text editor. A text editor is a software

CS 5160 Programming Assignment 3 Linked Lists In this programming assignment you will implement a rudimentary line-oriented text editor. A text editor is a software application that contains a collection of commands for manipulating a sequence of buffers of text. Typically when a file is opened the lines of text are loaded into the buffers and then various combinations of keystrokes are used to trigger operations on the buffers such as delete a line, insert a new line and so forth. Although there are a number of different approaches that are appropriate for implementing the editor, you are required to implement a solution using the myList class we developed in class. The content of each node in this list is a string containing a single line of text from the data file. lineEditor Commands The line text editor class should provide public member functions that allow us to process the commands listed below. When a command requires a line number, assume the list nodes are numbered from 1 to N where the first node is 1 and the last node is N. r filename Read the contents of the file called "filename" line-by-line and store the information in the text editor object (i.e. create the linked list of lines). If lines are already stored in the editor object, delete them before creating the new list of lines. w filename Write the contents of the list to the named file. This is a nondestructive operation i.e. the list should remain the same after writing the contents to the file. i n s Insert the string s into the list after line n. For example, it the command is: i 3 Hello World you should insert a new node in the list after the 3rd node that contains the string Hello World b s Insert a new line at the beginning of list containing the string s. a s Append a new line at the end of the list containing the string s. d n1 n2 Delete all lines of text from n1 to n2 inclusive (i.e. delete the sequence of list nodes from n1 to n2). j n Join the content of line n with line n+1 (i.e. join the contents of node n and n+1 deleting the empty node). Add one whitespace character between the contents of the joined lines. l n1 n2 List the content of lines n1 to n2 inclusive on the screen. Only print the content of the line with no additional information (e.g. no line number or other initial character) y n1 n2 Yank (copy) lines n1 to n2 inclusive into a temporary buffer. Each yank operation overwrites lines already in the buffer. p n Paste the contents of the temporary buffer after line n (insert nodes into the list after the nth node). If n is zero, paste at the beginning of the list F s Find and display all lines containing the string s. N Display the number of lines in the file. Q Terminate the program Error handing If you receive an invalid command code, ignore the command and discard anything remaining on the input line. Assume the lines are number 1 to N where N depends on the number of lines in the text file. If a command refers to a line number that does not exist, display an appropriate error message and ignore the command. Useful Information The following example illustrates opening a file called input.txt and echoing the contents to output.txt. #include ifstream input; ofstream output; string text; input.open( data.txt ); // open a file in the working directory for input output.open( output.txt ); // open a file in the working directory for output getline( input, text ); // reads a line of text into a string while ( !input.eof() ) // stop on end-of-file { output << text << endl; // write contents of a string to a file getline( input, text ); // get the next line of text } input.close(); // close the files output.close(); You will also want to review some of the functions available in the string class especially the find member function. Your Tasks You have several tasks in this assignment including: 1. Design the command processor to handle the set of commands listed above. 2. Design the lineEditor class with the appropriate set of member functions needed to satisfy the set of commands described above. Ideally you should have one public member function for each command, but notice a command like Q does not have anything to do with the lineEditor it terminates the program. 3. Implement the command processor and lineEditor class. Remember your implementation of the lineEditor class must use a myList list. Your implementation should be done in stages so you are developing and testing pieces of the solution. 4. Develop a test plan that exercises all of the commands to verify your implementation. On the assigned due date submit your solution via Pilot. We expect to receive a minimum of three files containing your source code: project3.cpp -- the command processor code lineEditor.cpp and/or lineEditor.h -- the lineEditor class and implementation myList.cpp and/or myList.h the myList class and implementation MyList #pragma once #include using namespace std; class dnode { private: dnode(string txt, dnode* forward = nullptr, dnode* backward = nullptr) { data = txt; next = forward; prev = backward; } void insertBefore(dnode* ahead) { next = ahead; prev = ahead->prev; ahead->prev->next = this; ahead->prev = this; } void remove() { next->prev = prev; prev->next = next; } string data; dnode* next; dnode* prev; friend class dlist; }; class dlist { public: dlist() { tail = new dnode("dummy"); tail->next = tail; tail->prev = tail; } dlist(const dlist& rhs) { copy(rhs); } ~dlist() { release(); } dlist& operator=(const dlist& rhs) { if (this != &rhs) { release(); copy(rhs); } return *this; } bool empty() const { return tail->next == tail; } void insertFirst(string text) { dnode* tmp = new dnode(text); tmp->insertBefore(tail->next); } void insertLast(string text) { dnode* tmp = new dnode(text); tmp->insertBefore(tail); } void removeFirst() { if (!empty()) { dnode* tmp = tail->next; tmp->remove(); delete tmp; } } void removeLast() { if (!empty()) { dnode* tmp = tail->prev; tmp->remove(); delete tmp; } } void print() const { dnode* tmp = tail->next; while (tmp != tail) { cout << tmp->data << " "; tmp = tmp->next; } cout << endl; } private: void copy(const dlist& rhs) { tail = new dnode("dummy"); tail->next = tail; tail->prev = tail; dnode* tmp = rhs.tail->next; while (tmp != rhs.tail) { insertLast(tmp->data); tmp = tmp->next; } } void release() { while (!empty()) { removeFirst(); } delete tail; } dnode* tail; };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!