Skip to main content
留学咨询

辅导案例-CSC161

By May 15, 2020No Comments

2020/4/3 CSC161 www.cs.grinnell.edu/~johnsonba/CSC161/2020S/homework/homework3.html 1/3 Home Schedule Class Slides Homework DeadlinesLabs and Projects CSC 161 – Imperative Problem Solving Homework 3 – Calculating Maximum Hourglass This homework is to be done individually. You may ask your instructor for help, but do not ask other students, tutors, or mentors for assistance. You also may not refer to any other materials to help you with this program, except for your textbook and course website materials (if you use them, cite the reference). 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 projects and homework, the style guidelines apply to this assignment, and points may be deducted for poor style, readability, and testing. Feedback will be given using a version of this checklist. 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 2020/4/3 CSC161 www.cs.grinnell.edu/~johnsonba/CSC161/2020S/homework/homework3.html 2/3 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. Reminder: you may NOT use global variables for this or any subsequent assignments; using a global variable will result in -5 points. Other stipulations are found in the style guidelines. The General Grading Form applies to this program project. This project will be worth 20 points, based on the following criteria: [1 point] Message to user about purpose of program [1 point] Reminds user of the format for entering data [2 points] Reads input from the user and checks that each entry is an integer [2 points] Error message and exits if input is not correct [3 points] Calculates the hourglasses using a function that takes the array as a parameter [3 points] Find the maximum hourglass in the array [2 points] Prints result with explanation 2020/4/3 CSC161 www.cs.grinnell.edu/~johnsonba/CSC161/2020S/homework/homework3.html 3/3 [2 points] Ensures that the array bounds are checked while calculating the hourglass sums [4 points] Tests a variety of arrays containing positive and negative numbers as well as zeros This derivative work is used and licensed under a Creative Commons Attribution-NonCommercialShareAlike 4.0 International license. The original is by Henry Walker, except where noted; other material is provided by Jerod Weinman and used with permission.

admin

Author admin

More posts by admin