Download presentation
Presentation is loading. Please wait.
Published byBrook Lambert Modified over 8 years ago
1
Multidimensional Array Sample Projects
2
Grading Program Objective: write a program that grades multiple-choice test
3
Grading Program Patterns: – Iterate 2D array – Sum up rows Modifications: – Break into functions – Record student scores in arrays – Get rid of i/j?
4
Nearest Points Rows : Points Cols : x, y
5
Nearest Points Patterns: – Not all array dimensions going to be looped over – Iterate through one array twice Compare item i to item i+1…end – Find smallest pattern
6
Nearest Points Modification: – Clean up indices – Constants for x and y instead of magic numbers: VS:
7
Sudoku Each number must be unique in Row/Col/Square
8
Sudoku Each number must be unique in Row/Col/Square
9
Sudoku Each number must be unique in Row/Col/Square
10
Map column to square 0 / 3 = 0 1 / 3 = 0 2 / 3 = 0 3 / 3 = 1 4 / 3 = 1 5 / 3 = 1 6 / 3 = 2 7 / 3 = 2 8 / 3 = 2 Sudoku 012345678 0 1 2 3 4 5 6 7 8 0 1 2
11
Sudoku Squares start at 0, 3, 6 0 / 3 * 3 = 0 1 / 3 * 3 = 0 2 / 3 * 3 = 0 3 / 3 * 3 = 3 4 / 3 * 3 = 3 5 / 3 * 3 = 3 6 / 3 * 3 = 6 7 / 3 * 3 = 6 8 / 3 * 3 = 6 012345678 0 1 2 3 4 5 6 7 8 0 1 2
12
Sudoku Patterns – Flag… look for reason to say false – Avoid self check
13
Sudoku Critique – row vs currentRow – i as parameter name
14
Temperature/Humidity File has day / hour / temperature / humidity Find daily averages Uses 3-D array: data[DAY][HOUR][TEMP/HUMIDITY]
15
Temp Patterns: – Change human numbers to array index:
16
Temperature/Humidity Critiques: – Don't need array for job as stated – Would two 2D arrays be better? – No
17
Find Local Maxima Objective : print all cells that are strictly greater than 4 direct neighbors Something is missing!!
18
Find Local Maxima Sanity check indices when appropriate:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.