CS 631 - Computing Fundamentals II - Spring 2005
Programming Assignments


Loyola College > Department of Computer Science > CS 631 > Programming Assignments > Programming Assignment 1

Plain Finder

Due

Tuesday, February 15th at the beginning of class. Email an electronic copy by attaching each .cpp and .h to the email. In addition, turn in a printout of the code. Be sure to include the Honor Code Statement: "I hereby declare that I have abided by the Honor Code during this assignment."

Introduction

The objective of this assignment is to create a program that finds the largest plain (area of land at a single elevation) on a topological map using a recursive algorithm. We will assume that our input is a 10x10 table where each entry represents the average elevation for a relatively small region on a map. In order for multiple regions to be part of the same plain, they must have the same elevation and be adjacent in either the north/south or east/west direction. The program should output the coordinates of one of the regions in the largest plain and the number of regions included in that plain. For example, if the table had the following data:
0       0       2       0
2       1       1       0
2       2       2       1
2       1       1       2
then the largest plain includes five regions, one of which is the region in row 2, column 1. (The upper right region is (1,1).) The output should therefore look something like this:
Largest plain: 5
Location: (2,1)

Assignment

  1. Design your program using a modular approach, which may include classes and/or structs if you wish. You are not allowed to use global variables, although you may define global constants.
  2. Your program should first call a function announce to describe the purpose of your program.
  3. The program will then prompt the user to enter a file name that contains the elevations of the regions. All maps will have 100 (10x10)regions. The file will be formatted in such as way that ten numbers appear on each line, and the numbers will be separated by tabs. The file will contain ten such lines.
  4. Store the information in a 2-dimensional array. You may assume that all elevations will be whole numbers.
  5. Create a recursive solution to find the largest plain. In general, you will need to calculate the size of each plain. Once you have determined the size of a particular plain, you should never recalculate its size. (Hint: You will need to keep track of which regions have been counted.)
  6. Output the size of the largest plain, and one of the regions belonging to that plain.

Grading

Sample Map Files

map1
map2
map3

Sample Solution

PlainFinder.h
PlainFinder.cpp
PlainTester.cpp