217k views
2 votes
Note: Implement the following 3 programs using either Java, C ++ or Python. Also design the logic of the problems using either flowchart or pseudocode. 1. Write a program that opens a specified text file then displays a list of all the unique words found in the file. Store each word as an element of a set. 2. Write a method, removeAt, that takes three parameters: an array of integers, the length of the anay, and an integer, say, index. The method deletes the array element indicated by index. If index is out of range or the array is empty, output an appropriate message.

User Grafthez
by
7.6k points

1 Answer

3 votes

Final answer:

The student is asked to develop two programs: one for listing unique words from a text file, and another to remove an array element at a specified index. Examples provided are in Python, including error handling for the second task.

Step-by-step explanation:

The question relates to programming, tasking the student to write programs in Java, C++, or Python for two different problems and to develop the logic using flowcharts or pseudocode. The first task involves writing a program that opens a text file, reads its contents, and displays a list of all the unique words found in the file using a set data structure. The second task is to write a method named removeAt that manipulates an array of integers, specifically removing an element at a specified index and handling errors related to index out-of-bound or empty array scenarios.

Example for Program 1 in Python:

def unique_words(filename):
with open(filename, 'r') as file:
words = set(file.read().split())
print("\\Unique words in file:", words)

unique_words('sample.txt')

Example for Program 2 in Python:

def removeAt(arr, length, index):
if 0 <= index < length:
arr.pop(index)
length -= 1
return arr
else:
return "Index out of range or array is empty"
User Ptival
by
7.7k points