A common task in array processing is to traverse a list and eliminate an undesired value. You will be provided with a text file named compact.txt, which contains non-negative (≥0) integers in random order. The number of integers in the file is not given, but it is no more than 100.
-
Write a program that reads a text file (compact.txt) and stores the integers in an array. Your instructor will provide this text file.
-
Write a method compact
that removes all zeroes from the array, leaving the order of the other elements unchanged. All local variables within this function must be scalar. In other words, you may not use a second array to solve the problem.
-
Do not solve the problem by printing out only the non-zero values in the array. The compact
method must remove all zeros from the array.
-
Print out the list both before and after removing the zeros. For example:
Before: 0, 9, 7, 0, 0, 23, 4, 0
After: 9, 7, 23, 4
Your program must use proper modular design and parameter passing.