Using file input implementation methods covered, write a program that reads a list of decimal values from an input file named inFile.in. The first number in the input file corresponds to the size of the 1-d array. Every number after the first number refers to the values to be stored in the array. Write the definition of a method named printReverse that takes 1-d array as its parameter and outputs the contents of the array in reverse.



Answer :

Here's a Python program that reads a list of decimal values from an input file named `inFile.in`, where the first number corresponds to the size of the 1-d array, and then prints the contents of the array in reverse:

```python
def printReverse(arr):
# Print the array in reverse order
for i in range(len(arr) - 1, -1, -1):
print(arr[i], end=" ")

def main():
# Open the input file
with open('inFile.in', 'r') as file:
# Read the size of the array
size = int(file.readline().strip())

# Read the decimal values and store them in the array
arr = [float(file.readline().strip()) for _ in range(size)]

# Call the printReverse method to print the array in reverse
printReverse(arr)

if __name__ == "__main__":
main()
```

Ensure that the input file `inFile.in` exists and contains the correct format of values, with the first number representing the size of the array and subsequent numbers representing the values to be stored in the array. The program will read the contents of the file, store them in an array, and then print the array in reverse order using the `printReverse` method.

Other Questions