Homework 4 - Calculating Maximum Hourglass

Please review the rules on collaboration for homework for this course, as well as the guidelines for turning in work.

This assignment is designed to give you practice in working with two-dimensional arrays and bounds checking.

See the "Grading" section below for specific criteria for this assignment. As with all homework, the style guidelines apply to this assignment, and points may be deducted for poor style, readability, and testing.

Learning outcomes

Upon completion of this assignment, students will demonstrate understanding of the followinglearning outcomes:

1. In the context of low-level, systems programming: 2. Architect and analyze stateful programs: 3.Productively develop software within a Unix-style command-line interface (CLI): 8. Author small, memory-safe programs that interact with the world:

Overview

This project will deal with a 6 x 6, two-dimensional array of integers (although it would be pretty easy to extend this to an arbitrary sized array). The program will traverse the two-dimensional array, A, calculating the sums of numbers located in a particular pattern (the hourglass, defined below) surrounding each location A[i][j] and reporting the greatest sum that is found.

This sort of array traversal and calculation may be found in a variety of situations, such as reporting and updating the status of the squares surrounding characters in a map-based videogame or in managing simulations of bacteria.

Input Format

For this assignment, we will stick with a 6 x 6 array of integers. The integers may range from -9 to 9, including 0. As you read in the input, you must check that you only encounter integers. If the user makes a mistake in input, you should print an error message and quit.

The user will enter the array from standard input (stdin) as 6 rows of 6 integers, with a space between each integer and a newline (return) character separating each row.

For instance:

1 0 0 0 0 0
2 1 0 0 0 0
3 2 1 0 0 0
4 3 2 1 0 0
5 4 3 2 1 0
6 5 4 3 2 1

Output Format

The program should output a single value: the largest of the hourglass sums. For the example array above, your output might look like:

The largest hourglass sum is: 28

What Your Program Needs to Do

An hourglass is defined to be all the values in this pattern:

a b c
  d  
e f g

An hourglass sum is the result of adding all of the integers (a through g) in each hourglass. In a 6 x 6 array, there are 16 hourglasses, and hence, there are 16 sums to calculate. Since this calculation needs to be done repeatedly, this is a great place to use a function!!

Testing

Test your program with both positive and negative values. You should also be sure to test arrays that contain zeros.

Grading

I highly recommend that for this (and all coding projects) that you make a testing plan before you start to write code. You do not need to plan to test all possible inputs to the two programs, but you should have a plan that will test major sections of your code and demonstrate your problem solving skills. Include this plan when you submit your code and testing transcript.

This project will be worth 20 points, based on the following criteria: