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 - for left

r - for right

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 - for back

i c - for insert character c

h for home e for end

u for undo (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: The user will enter the $ character when they are done.

___Header__

Cursor.h

#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

Need cursor.cpp and main.cpp

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

How does lean eliminate waste? L025

Answered: 1 week ago