Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will create a class similar to the List ADT. Simulate a simple text editor, which stores a string of characters using

In this assignment, you will create a class similar to the List ADT.

Simulate a simple text editor, which stores a string of characters using the List ADT which has been endowed with some additional features. We will call this endowed List ADT as a Cursor class. Normally, you would implement the Cursor class using inheritance, that is, the Cursor class would be a derived class of the List ADT which would serve as the base class. However, in this assignment we will implement the Cursor class from scratch and model it after the List ADT.

You must use a singly linked list. Do not use any iterators to traverse the list. The reason is I want you to manipulate the linked lists directly.

Your editor should support the following operations and redisplay the current text (that is, the list) after performing any one of them.

left : move cursor left one character (or do nothing if at the beginning of the text)

right : move cursor right one character (or do nothing if at the end of the text)

delete : delete the character to the right of the cursor (or do nothing if at the end of

the text)

back : delete the character to the left of the cursor (or do nothing if at the

beginning of the text)

insert c : insert the character c just after the cursor.

home: move cursor to the beginning of the text (or do nothing if at the beginning

of the text)

end: move cursor to the end of the text (or do nothing if at the end of the text)

undo: undo the last insert/delete/back operation

(You can assume that between any two consecutive undo commands issued by the user, there will be at least one insert/delete/back operation.)

The Cursor class definition is provided to you. You can only add member variables or member functions to the definition provided. You cannot remove any declaration from the class definition1. You have to write the implementation for the Cursor class and a driver program that will allow the user to enter text to use your text editor. The user will input:

l-forleft r-forright

d - for delete

1 If you need to make any deletions because of recent updates to the C++ language, please bring it to my attention immediately.

b-forback

i c - for insert character c

hforhome

eforend

uforundo (l, r, d, b, i, h, e and u will be input in lower case only)

After each of the above operations you will display the entire text with a | indicating where the cursor is currently positioned.

For example, the following table gives a sequence of user commands and what will be displayed after each command:

user command

Displayed text

id

d|

ia

da|

it

dat|

ia

data|

l

dat|a

l

da|ta

b

d|ta

r

dt|a

u

da|ta

b

d|ta

ie

de|ta

il

del|ta

The user will enter the $ character when they are done.

(FIRST EXTRA CREDIT 50 points) Allow the user to undo up to the last 10 insert/delete/back operations. (Hint: You will have to use a stack for this.). For this, you cannot assume that between any two consecutive undo commands issued by the user, there will be at least ten insert/delete/back operations.

(SECOND EXTRA CREDIT 50 points) Allow the user to delete/back a contiguous group of characters this command will be specified by d or b followed by a number. For e.g., d5 will delete 5 characters counting forward from the current position of the cursor. You can assume a valid number will be input. That is, if the user inputs d5, you can assume that there are at least 5 characters counting forward from the current position of the cursor. Note that if you choose to implement this option, the undo operation should work in this case also (just like in a real editor such as Word).

#ifndef CURSOR_H #define CURSOR_H // Cursor class. // ******************PUBLIC OPERATIONS******************************************************************************** // bool isEmpty( ) --> Return true if empty; else false // void makeEmpty( ) --> Remove all items // void left( ) --> Move cursor one position left or do nothing if already at beginning of text // void right( ) --> Move cursor one position right or do nothing if already at end of text // void del( ) --> Delete node after current cursor position or do nothing if already at end of text // void back( ) --> Remove node before current cursor position or do nothing if already at beginning of text // void insert( x ) --> Insert x after current cursor position // void home( ) --> Move cursor to the beginning of text or do nothing if already at beginning of text // void end( ) --> Move cursor to the end of text or do nothing if already at end of text // void undo( ) --> Undo the last delete/back/insert operation // *******************PRIVATE OPERATIONS****************************************************************************** // void printText ( ) --> This will print the entire contents of the list. This is a private member function. // This will be called by each of left(), right(), del(), back() and insert(). //******************************************************************************************************************** template  class Cursor; //forward declaration. template  class CNode { CNode( const Object & theElement = Object( ), CNode * n = nullptr ): element( theElement ), next( n ) { } Object element; CNode *next; friend class Cursor; }; template  class Cursor { public: Cursor( ); bool isEmpty( ) const; void makeEmpty( ); void left ( ); void right ( ); void del ( ); //This is the delete operation. I named it del instead of delete as delete conflicts with a C++ keyword. void back ( ); void insert( const Object & x ); void home ( ); void end ( ); void undo ( ); private: void printText ( ) ; CNode *header; CNode *cursorPosition; }; #endif                        
                                            
                    

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions