logo Use CA10RAM to get 10%* Discount.
Order Nowlogo

write basic text editor allows you to add, delete, and modify lines of text Use a list of strings to store the lines, with each list element being one line.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

This task is to write a very basic text editor. It allows you to add, delete, and modify lines of text.  Use a list of strings to store the lines, with each list element being one line. The elements of the list are modified according to the commands given by the user.

 

The editor repeatedly:
1.    displays the lines entered so far prefixed with a line number in front of each and ending with an empty line.
2.    it waits for the user to enter a command
3.    if it's a valid command, it modifies the list appropriately
4.    go back to step #1

Initially, the list of lines will be empty.

You should have a function for each of the commands below, except for Quit.

The valid commands are:

 

a - add a line
Lines from the user are added to the lines collected so far. All lines entered are added to the list until the user enters a line containing a single #. 

d - delete a line
Prompt for a line number and then delete that line. Use the Python command del to delete a line from the list of lines. Check that the line number entered is valid. If it is invalid, ask for a line number again.

r - replace a line
Prompt for a line number and then replace that line with a new one from the user. Check that the line number entered is valid. If it is invalid, ask for a line number again.

f - find and replace a string
Prompt for one string (the search pattern) and then a second (the replacement). Replace all occurrences of the first string with the second, using string.replace() .

p – copy/paste lines
Prompt for two line numbers, one is the starting line of text to copy, and the second is the end line of the text to copy. Slice this part of the list, and add it to the end of the list as a single string.
Check that the line numbers entered are valid. If they are invalid, ask for a line numbers again.

c - Clear all
Delete all lines, so the state is like when the program starts.

q - Quit
End the program.

***Clarification on line numbers*** You can expect that any line numbers entered for the above functions are integers. You do NOT need to test if they are non-integer inputs, but just that they are in range of the line numbers that exist.

 

Here's an example of this editor in use. Several commands are shown. Initially, before the 'a' (add) command is used, there aren't any lines, so nothing is output before the command prompt.

Command a, d, r, f, p, c, q: a
Add a line: It is a lovely morning
Add a line: for a walk.
Add a line: It is a lovely evening
Add a line: for reading a book
Add a line: in front of the fire.
Add a line: #
1: It is a lovely morning
2: for a walk.
3: It is a lovely evening
4: for reading a book
5: in front of the fire.

Command a, d, r, f, p, c, q: d
Line number: 5
1: It is a lovely morning
2: for a walk.
3: It is a lovely evening
4: for reading a book

Command a, d, r, f, p, c, q: r
Replace line number: 2
Replacement string: for a walk in the park.
1: It is a lovely morning
2: for a walk in the park.
3: It is a lovely evening
4: for reading a book

Command a, d, r, f, p, c, q: f
Find string: lovely
Replace with: wonderful
1: It is a wonderful morning
2: for a walk in the park.
3: It is a wonderful evening
4: for reading a book

Command a, d, r, f, p, c, q: p
Start line number: 7
End line number: 8
Start line number: 1
End line number: 2
1: It is a wonderful morning
2: for a walk in the park.
3: It is a wonderful evening
4: for reading a book
5: It is a wonderful morning for a walk in the park.

Command a, d, r, f, p, c, q: c

Command a, d, r, f, p, c, q: q

For example:

 

Input

Result

a

It is a lovely morning

for a walk.

It is a lovely evening

for reading a book

in front of the fire.

#

d

5

r

2

for a walk in the park.

f

lovely

wonderful

p

7

8

1

2

c

q

Command a, d, r, f, p, c, q: a

Add a line: It is a lovely morning

Add a line: for a walk.

Add a line: It is a lovely evening

Add a line: for reading a book

Add a line: in front of the fire.

Add a line: #

1: It is a lovely morning

2: for a walk.

3: It is a lovely evening

4: for reading a book

5: in front of the fire.

 

Command a, d, r, f, p, c, q: d

Line number: 5

1: It is a lovely morning

2: for a walk.

3: It is a lovely evening

4: for reading a book

 

Command a, d, r, f, p, c, q: r

Replace line number: 2

Replacement string: for a walk in the park.

1: It is a lovely morning

2: for a walk in the park.

3: It is a lovely evening

4: for reading a book

 

Command a, d, r, f, p, c, q: f

Find string: lovely

Replace with: wonderful

1: It is a wonderful morning

2: for a walk in the park.

3: It is a wonderful evening

4: for reading a book

 

Command a, d, r, f, p, c, q: p

Start line number: 7

End line number: 8

Start line number: 1

End line number: 2

1: It is a wonderful morning

2: for a walk in the park.

3: It is a wonderful evening

4: for reading a book

5: It is a wonderful morning for a walk in the park.

 

Command a, d, r, f, p, c, q: c

 

Command a, d, r, f, p, c, q: q

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

639 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

624 Answers

Hire Me
expert
Husnain SaeedComputer science

782 Answers

Hire Me
expert
Atharva PatilComputer science

978 Answers

Hire Me