Skip to main content
ICT
A16 - Single Dimension Arrays
 
Main   Previous
 

LAB ASSIGNMENT A16.2 page 10 of 10

Compact

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. 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. Your instructor will provide this text file.

  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 zeros from the array.

Instructions:

  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 use proper modular design and parameter passing.

 

Main   Previous
Contact
 © ICT 2006, All Rights Reserved.