Skip to main content
Lesson 19 - Single Dimension Arrays
Lesson MenuPrevious
  
L.A.19.2 - Compact page 11 of 11

Background:

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. A text file of integers is provided. The number of integers in the file is not given, but it is no more than 100.

Assignment:

  1. Write a program that reads a text file (compact.txt) and stores the integers in an array. This text file will be provided by your instructor.

  2. 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.

  3. Do not solve the problem by printing out only the non-zero values in the array. The compact method must remove all zeroes from the array.

Assignment:

  1. 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
  2. Your program must utilize proper modular design and parameter passing.


Lesson MenuPrevious
Contact
 ©ICT 2003, All Rights Reserved.