Skip to main content
ICT
Lesson AB24 - Recursive Array Programming
 
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 AB24.1 page 7 of 7

EraseObject

Background:

An image can be represented as a grid of black and white cells. An object in the image is defined as a group of connected black cells that touch on one side (Please note: cells are not connected if they only touch at a corner). The diagram below represents an image that contains two objects, therefore, and one of them consists of a single cell.

A way to test whether a group of cells is an object (within an image) is to ask:

  • Can you move from any black cell in the group to any other black cell in the group by moving one square at a time, keeping on black cells the whole way?
  • Each move must be up, down, left, or right; diagonal moves are not allowed.
  • If you can, then the group of black cells is an object (not to be confused with a Java object!).

Many drawing or graphic programs include erasing features. With such an eraser tool, an object can be completely erased by double-clicking on that object with a mouse.

This problem involves erasing an object stored as a collection of black squares in a matrix image.

Assignment:

  1. The first entry in the provided text file (digital.txt) is the number of pairs that follow (i.e., 55). Each subsequent line contains a pair of integers, separated by a blank space. Each pair is a row and column coordinate that specifies the location of a black cell in the starting grid. The row and column values range from 1 to 20.

  2. Write a program that accomplishes the following:

    1. Load the text file digital.txt representing the 20 x 20 grid of black and white squares.

    2. Ask the user for the starting coordinate of an attempted erasure. If this starting coordinate is part of an object, the program should erase the entire object (change black to white).

    3. Print out the grid afterwards.

Instructions:

  1. The left hand image is the result of loading the data from digital.txt. After loading the data file, print out the image.

  2. Erase any one of the objects; print out the remaining two objects.

  3. Erase any one of the remaining two objects; print out the single remaining object.

 

Main Previous
Contact
 © ICT 2006, All Rights Reserved.