Skip to main content
ICT
A16 - Single Dimension Arrays
 
Main Previous
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

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.