# Figure 6 5 flowchart and pseudocode of decision

• Notes
• 46
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 11 - 25 out of 46 pages.

Figure 6-5 Flowchart and pseudocode of decision-making process using an array—but still a hard way
How an Array Can Replace Nested Decisions (continued) 12 Programming Logic and Design, Seventh Edition Figure 6-6 Flowchart and pseudocode of efficient decision- making process using an array
13 Programming Logic and Design, Seventh Edition Figure 6-7 Flowchart and pseudocode for Dependents report program
How an Array Can Replace Nested Decisions (continued) Figure 6-7 Flowchart and pseudocode for Dependents report program (continued) 14 Programming Logic and Design, Seventh Edition
Using Constants with Arrays Use constants in several ways To hold the size of an array As the array element values As an array subscript 15 Programming Logic and Design, Seventh Edition
Using a Constant as the Size of an Array Avoid “magic numbers” (unnamed constants) Declare a named numeric constant to be used every time the array is accessed Make sure any subscript remains less than the constant value Constants are created automatically in many languages 16 Programming Logic and Design, Seventh Edition
Using Constants as Array Element Values Sometimes the values stored in arrays should be constants Example string MONTH[12] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" 17 Programming Logic and Design, Seventh Edition
Using a Constant as an Array Subscript Use a numeric constant as a subscript to an array Example Declare a named constant as: num INDIANA = 5 Display value with: output salesArray[INDIANA] 18 Programming Logic and Design, Seventh Edition
Searching an Array for an Exact Match Sometimes you must search through an entire array to find a value Example: mail-order business Item numbers are three-digit, non-consecutive numbers Customer orders an item; check if item number is valid Create an array that holds valid item numbers Search the array for an exact match 19 Programming Logic and Design, Seventh Edition
20 Programming Logic and Design, Seventh Edition Figure 6-8 Flowchart and pseudocode for a program that verifies item availability
21 Programming Logic and Design, Seventh Edition Figure 6-8 Flowchart and pseudocode for a program that verifies item availability (continued)
22 Programming Logic and Design, Seventh Edition Figure 6-8 Flowchart and pseudocode for a program that verifies item availability (continued)
Searching an Array for an Exact Match (continued) Flag : a variable that indicates whether an event occurred Technique for searching an array Set a subscript variable to 0 to start at the first element Initialize a flag variable to false to indicate the desired value has not been found Examine each element in the array If the value matches, set the flag to True If the value does not match, increment the subscript and examine the next array element 23 Programming Logic and Design, Seventh Edition
Using Parallel Arrays Example: mail-order business Two arrays, each with six elements Valid item numbers Valid item prices Each price in the valid item price array is in the same position as the corresponding item in the valid item number array Parallel arrays