Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Python Expert

Task 1

Implement a complete version of an Array-Based List. Use 50 as the maximum number of elements. To create arrays use the method build_array from referential_array.py as discussed in the Lectures. Your List should include implementations for the following 10 functions:

- str (self): Returns a string representation of the list. Structure the string so that there is one item per line. Called by str(self)
- len (self): Returns the length of the list. Called by len(self)
- contains (self, item): Returns True if item is in the list, False otherwise. Called by item in self
- getitem (self, index): Returns the item at index in the list, if index is non-negative. If it is negative, it will return the last item if index is -1, the second-to last if index is -2, and so on up to minus the length of the list, which returns the first item. The function raises an IndexError if index is out of the range from -len(self) to len(self). Called by self[index]
- setitem (self, index, item): Sets the value at index in the list to be item. The index can be negative, behaving as described above. Raises an IndexError if index is out of the range from
-len(self) to len(self). Called by self[index] = item
- eq (self, other): Returns True if this list is equivalent to other. Called by self == other

- append(self, item): Adds item to the end of the list. Remember the underlying array is and should remain of fixed size. The operation should raise an Exception if the list is full.
- insert(self, index, item): Inserts item into self before position index. The index can be negative, behaving as described above. Raises an IndexError if index is out of the range from -len(self) to len(self).
- remove(self, item): Deletes the first instance of item from the list. Raises a ValueError if item does not exist in self
- delete(self, index): Deletes the item at index from the list, moving all items after it towards the start of the list. The index can be negative, behaving as described above. Raises an IndexError if index is out of the range from -len(self) to len(self).
- sort(self, reverse): Sorts the items in the list in ascending order if reverse is False or descending order if is reverse is True. Pick your favourite sorting algorithm from those covered in the Lectures.

Task 2

Modify your list implementation so that the size of the underlying array is dynamic. The base size of the array is 20 and should never be less than 20. However, if the list becomes full, it is resized to be 2 times larger than the current size. Likewise, the underlying size should decrease by half if the underlying array is larger than the base size but the content occupies less than 1 of the available space. When resizing the list, retain the contents of the list. That is, when it is initially filled, it will be resized to 20 items, then 40, while retaining the contents initially in it. The same happens when the size of the array shrinks.

Task 3

Implement a function that takes a filename as input and reads it into an instance of the class you implemented on Task 2. For each line in the file, store it as a single item in the list.

Background
The editor ed was one of the first editors written for UNIX. In this prac we will use the Array-Based list to implement a version of a line-oriented text editor based on ed. The text editor ed is very similar to the common UNIX text editors vi and vim (it is in fact their
predecessor).

Important: Our commands will be different from the ed commands.

To implement a simple line-oriented text editor, the idea is as follows. Suppose a file contains the following lines:

Yossarian decided not to utter another word.

where the string "Yossarian decided" is considered to be in line 1, "not to utter" is considered to be in line 2, etc. We want to store every line in the file in a data type that allows users to easily manipulate (delete/add/print) any line by simply providing the line number they want to modify. This means we should use a list data type (as opposed to a stack or a queue).

Task 4
Write a text editor as a Python program that allows a user to perform the 6 commands shown below using a menu. It is advisable that the Editor itself is a class with an attribute containing an list of lines. The list should be the type you have implemented on Task 2.

insert num: which inserts a line of text (given by the user) in the list before position num, and raises an exception if no num is given
read filename: which opens the file, filename, reads all the lines in from the file, put each line as a separate item into a list, and then closes the file.
write filename: which creates or opens a file, filename, writes every item in the list into the file, and then closes the file.
print num1 num2: which prints the lines between positions num1
and num2, if num1 < num2.
delete num: which deletes the line of text in the list at position num, and deletes all the lines if no num is given.
search word: which takes a word and prints the line numbers in which the target word appears. Search should be case insensitive.
Search should work as expected in a standard text editor, for example ignoring punctuation. This function must be accessible through the menu via commands search and count.
quit: which quits the program.

Important: All errors should be caught and a question mark, ?, should be printed when an error occurs. Negative number lines are possible and should be handled following the convention described for the original list implementation. For example, num = -1 refers to the last line of the text.

Tip: When you are testing your code, it is handy to have a source of reasonably large text files that you can use as test data. There is a huge repository of public domain text files at Project Gutenberg's websites. The Australian Project Gutenberg repository is at gutenberg website. You are encouraged to download a couple of ebooks from here and use them to make sure your code can deal with large files. Be sure to download plain-text format, though - your program is not expected to deal with other formats.

Task 5

Re-implement your editor using a Linked List instead of an Array-based list. The idea is to re-create the ADT now using the linked structure. If done properly, switching your text-editor to a Linked List implementation should take no more than changing a single line. To ensure this, make sure that the List ADT is implemented with the same functions and function signatures in both, Array-based and Linked versions. Write a page of text, using what you know of theory to analyse how the performance of your text editor would change when switching implementations.

Task 6

The sequence of actions made in a text editor can be stored during execution to facilitate undoing actions. When a user chooses to undo an operation the most recent action should have its changes reversed. This indicates that a last in, first out data structure would be suitable for storing the actions.

Implement a Stack ADT based Linked Nodes, and use it to implement in your editor the undo feature. Add this to your menu using the command undo.

Python, Programming

  • Category:- Python
  • Reference No.:- M92479420
  • Price:- $90

Priced at Now at $90, Verified Solution

Have any Question?


Related Questions in Python

Lab assignment -background - we have discussed in detail

Lab Assignment - Background - We have discussed, in detail, the function of Stacks and Queues and how they are specifically implemented in Python. To get a better understanding of the utility of these data structures, we ...

Questionwhat is a python development frameworkgive 3

Question What is a python development framework? Give 3 examples python development framework used today. and explain which development framework is used in which industry.

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

Environment setupthe first mini project will be based on

Environment Setup The first mini project will be based on Ladder Logic programming. We will be using Schneider Electric's IDE called SoMachine Basic to do the programming. The latest ver- sion of SoMachine Basic for Wind ...

Question why is software configuration management

Question : Why is software configuration management considered an umbrella activity in software engineering? Please include examples and supporting discussion. The response must be typed, single spaced, must be in times ...

Quesiton write a python script that counts occurrences of

Quesiton: Write a python script that counts occurrences of words in a file. • The script expects two command-line arguments: the name of an input file and a threshold (an integer). Here is an example of how to run the sc ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Project reconnaissance and attack on ics

Project: Reconnaissance and Attack on ICS NetworksEnvironment Setup The second mini project will be based on Industrial Network Protocols, specifically the Modbus protocol. Please follow the instructions carefully to set ...

Question a software company sells a package that retails

Question : A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10 - 19 20% 20 - 49 30% 50 - 99 40% 100 or more 50% Write a program usi ...

Tasksdemonstrate data scraping of a social network of

Tasks Demonstrate data scraping of a social network of choice. Develop technical documentation, including the development of the code & detailing the results. Provide a report on the findings, that includes research into ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As