Python
DESCRIPTION
Write a program that will read an array of integers from a file and do the following:
●
Task 1: Revert the array in N/2 complexity time
(i.e., number of steps)
.
●
Task 2: Find the maximum and minimum element of the array.
INPUT OUTPUT
Read the array of integers from a file named “
inputHW1.txt
”. To do this, you can use code snippet
from the “
file.py
” file. This file is provided in
Canvas. Copy the “
read
” function from this file and
paste it to your program file. Then, if you call the read function like the following:
numbers = read()
# The following "read" function reads values from a file named "inputHW1.txt" and
returns the values in an array.
def read():
file = open("inputHW1.txt", "r")
line = file.readline()
values = []
for value in line.split(' '):
values.append(int(value))
return values
the integers will be read from file and loaded in the numbers array.
Now, print the reverted arra
y, minimum element and maximum element of the array.
For example, if the input array is: 1 4 9 11 8 3 2 5 10
the following will be printed on the screen:
Reverted array: 10 5 2 3 8 11 9 4 1
Maximum element: 11
Minimum element: 1
EXTRA CREDIT - 30%
Find the trend change points of the array. You will get
30% extra credit
for doing this task.
Trend
change points are those points where the array
changes its direction
and
goes from
increasing to decreasing order or decreasing to increasing order.
Note that, you have to find the trend change points of the input array, not the reverted array.
For example, if the input array is: 1 4 9 11 8 3 2 5 10
the following will be printed on the screen:
Trend change points: 11 8 5
def read():
file = open("./inputHW1.txt", "r")
line = file.readline()
values = []
for value in line.split(' '):
values.append(int(value))
return values
def revert(input_list):
if len(input_list) == 1:
return input_list
reverted_list = [0] * len(input_list)
for i in range(int(len(input_list)/2)):
reverted_list[-1 *
(i+1)] = input_list[i]
reverted_list[i] =
input_list[-1 * (i+1)]
return reverted_list
def minimum(input_list):
min = input_list[0]
for i in range(1, len(input_list)):
if(input_list[i] <
min):
min = input_list[i]
return min
def maximum(input_list):
max = input_list[0]
for i in range(1, len(input_list)):
if(input_list[i] >
max):
max = input_list[i]
return max
def find_trend_change_points(input_list):
trend_increasing = False
if(input_list[0] < input_list[1]):
trend_increasing =
True
for i in range(1, len(input_list)-1):
if(input_list[i] <
input_list[i+1]) != trend_increasing:
print(input_list[i])
print("Reverted Array ")
print(revert(read()))
print("Minimum "+ str(minimum(read())))
print("Maximum " +str(maximum(read())))

Please ask your instructor to cross check the trend
points,
I believe according to the definition mentioned above, the trend
points for [ 1 4 9 11 8 3 2 5 10 ] should be 8,5
and not 11, 8, 5. Please reply back with a response and I can help
you score the extra credits too
Reverted Array [10, 5, 2, 3, 0, 11, 9, 4, 1] Minimum 1 Maximum 11
Python DESCRIPTION Write a program that will read an array of integers from a file and...
Write a program that will take input from a file of numbers of type double and output the average of the numbers in the file to the screen. Output the file name and average. Allow the user to process multiple files in one run. Part A use an array to hold the values read from the file modify your average function so that it receives an array as input parameter, averages values in an array and returns the average Part...
C++
3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...
required to write an assembly program to find the maximum of anarray of integers by doing the following:1. Prompt user to input array size n (n <= 10)2. Prompt user to input element values of array A one by one3. Display the result on the console.This program must at least include one function. The main program will read the valuesof the array (as user inputs the element values) and stores them in the memory (datasegments section) and at the end...
9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named...
Assume that an array A is given to you in a txt file. You should read it. If you think this is a time-dependent data, print the number of local minimums in the array to a txt file. Local minimum means the element which is less than the previous element and the following element. Please do not use any additional library. For example, if A=[3, 2, 9, 8, 7, 8, 6], the code should print 2 and 7. (Local minimums...
1. write a java program using trees(binary search treee) to read integers from input file( .txt) and add +1 to each number that you read from the input file. then copy result to another (.txt) file. example: if inpu File has numbers like 4787 79434 4326576 65997 4354 the output file must have result of 4788 79435 4326577 65998 4355 Note: there is no commas in between the numbers. dont give images or theory please.
Write a C++ that read a list of numbers from a .txt file into array. The first digit on the list will be array size, while the second number on the list will be our first number in our array list. Example: t1.txt file contain list off input number: 5, 3, 6, 10, 43, 23. notice the first number is 5 which will need to be use as an array size and the rest of the numbers are in the...
C++ programming language Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in...
PYTHON write a program that will open a file named data.txt and read each line of the file one at a time. Each line should be printed to the screen along with a line number
Write a C program as follows:
Single source code file
Calls a function with an arbitrary name (i.e. you name it) that
accepts two arrays of the same size
The function should add each element in the arrays together and
place the values in a third array
Each array element, each array address, and the sum are printed
to the screen in tabulated format with headersI also would like to request
that LOTS of comments be included, as I need...