🗊Презентация Programming Logic and Design Seventh Edition

Нажмите для полного просмотра!
Programming Logic and Design Seventh Edition, слайд №1Programming Logic and Design Seventh Edition, слайд №2Programming Logic and Design Seventh Edition, слайд №3Programming Logic and Design Seventh Edition, слайд №4Programming Logic and Design Seventh Edition, слайд №5Programming Logic and Design Seventh Edition, слайд №6Programming Logic and Design Seventh Edition, слайд №7Programming Logic and Design Seventh Edition, слайд №8Programming Logic and Design Seventh Edition, слайд №9Programming Logic and Design Seventh Edition, слайд №10Programming Logic and Design Seventh Edition, слайд №11Programming Logic and Design Seventh Edition, слайд №12Programming Logic and Design Seventh Edition, слайд №13Programming Logic and Design Seventh Edition, слайд №14Programming Logic and Design Seventh Edition, слайд №15Programming Logic and Design Seventh Edition, слайд №16Programming Logic and Design Seventh Edition, слайд №17Programming Logic and Design Seventh Edition, слайд №18Programming Logic and Design Seventh Edition, слайд №19Programming Logic and Design Seventh Edition, слайд №20Programming Logic and Design Seventh Edition, слайд №21Programming Logic and Design Seventh Edition, слайд №22Programming Logic and Design Seventh Edition, слайд №23Programming Logic and Design Seventh Edition, слайд №24Programming Logic and Design Seventh Edition, слайд №25Programming Logic and Design Seventh Edition, слайд №26Programming Logic and Design Seventh Edition, слайд №27Programming Logic and Design Seventh Edition, слайд №28Programming Logic and Design Seventh Edition, слайд №29Programming Logic and Design Seventh Edition, слайд №30Programming Logic and Design Seventh Edition, слайд №31Programming Logic and Design Seventh Edition, слайд №32Programming Logic and Design Seventh Edition, слайд №33Programming Logic and Design Seventh Edition, слайд №34Programming Logic and Design Seventh Edition, слайд №35Programming Logic and Design Seventh Edition, слайд №36Programming Logic and Design Seventh Edition, слайд №37Programming Logic and Design Seventh Edition, слайд №38Programming Logic and Design Seventh Edition, слайд №39Programming Logic and Design Seventh Edition, слайд №40Programming Logic and Design Seventh Edition, слайд №41Programming Logic and Design Seventh Edition, слайд №42Programming Logic and Design Seventh Edition, слайд №43Programming Logic and Design Seventh Edition, слайд №44Programming Logic and Design Seventh Edition, слайд №45Programming Logic and Design Seventh Edition, слайд №46

Содержание

Вы можете ознакомиться и скачать презентацию на тему Programming Logic and Design Seventh Edition. Доклад-сообщение содержит 46 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Programming Logic and Design
Seventh Edition
Chapter 6
Arrays
Описание слайда:
Programming Logic and Design Seventh Edition Chapter 6 Arrays

Слайд 2





Objectives
In this chapter, you will learn about:
Storing data in arrays
How an array can replace nested decisions
Using constants with arrays
Searching an array for an exact match
Using parallel arrays
Описание слайда:
Objectives In this chapter, you will learn about: Storing data in arrays How an array can replace nested decisions Using constants with arrays Searching an array for an exact match Using parallel arrays

Слайд 3





Objectives (continued)
Searching an array for a range match
Remaining within array bounds
Using a for loop to process arrays
Описание слайда:
Objectives (continued) Searching an array for a range match Remaining within array bounds Using a for loop to process arrays

Слайд 4





How Arrays Occupy Computer Memory
Array
A series or list of variables in computer memory
All variables share the same name
Each variable has a different subscript
Subscript (or index)
Position number of an item in an array
Subscripts are always a sequence of integers
Описание слайда:
How Arrays Occupy Computer Memory Array A series or list of variables in computer memory All variables share the same name Each variable has a different subscript Subscript (or index) Position number of an item in an array Subscripts are always a sequence of integers

Слайд 5





Each item has the same name and the same data type
Each item has the same name and the same data type
Element: an item in the array
Array elements are contiguous in memory
Size of the array: the number of elements it will hold
Subscripts or indexes: indicate the position of a particular element in the array
Adding data values is called populating the array
Описание слайда:
Each item has the same name and the same data type Each item has the same name and the same data type Element: an item in the array Array elements are contiguous in memory Size of the array: the number of elements it will hold Subscripts or indexes: indicate the position of a particular element in the array Adding data values is called populating the array

Слайд 6





How Arrays Occupy Computer Memory (continued)
Описание слайда:
How Arrays Occupy Computer Memory (continued)

Слайд 7





How an Array Can 
Replace Nested Decisions
Example: Human Resources Department Dependents report
List employees who have claimed zero through five dependents
Assume no employee has more than five dependents
Application produces counts for dependent categories 
Uses a series of decisions
Application does not scale up to more dependents
Описание слайда:
How an Array Can Replace Nested Decisions Example: Human Resources Department Dependents report List employees who have claimed zero through five dependents Assume no employee has more than five dependents Application produces counts for dependent categories Uses a series of decisions Application does not scale up to more dependents

Слайд 8


Programming Logic and Design Seventh Edition, слайд №8
Описание слайда:

Слайд 9





How an Array Can Replace 
Nested Decisions (continued)
The array reduces the number of statements needed
Six dependent count accumulators are redefined as a single array
Variable as a subscript to the array
Array subscript variable must be:
Numeric with no decimal places
Initialized to 0
Incremented by 1 each time the logic passes through the loop
Описание слайда:
How an Array Can Replace Nested Decisions (continued) The array reduces the number of statements needed Six dependent count accumulators are redefined as a single array Variable as a subscript to the array Array subscript variable must be: Numeric with no decimal places Initialized to 0 Incremented by 1 each time the logic passes through the loop

Слайд 10


Programming Logic and Design Seventh Edition, слайд №10
Описание слайда:

Слайд 11


Programming Logic and Design Seventh Edition, слайд №11
Описание слайда:

Слайд 12





How an Array Can Replace 
Nested Decisions (continued)
Описание слайда:
How an Array Can Replace Nested Decisions (continued)

Слайд 13


Programming Logic and Design Seventh Edition, слайд №13
Описание слайда:

Слайд 14





How an Array Can Replace 
Nested Decisions (continued)
Figure 6-7 Flowchart and pseudocode for Dependents report program (continued)
Описание слайда:
How an Array Can Replace Nested Decisions (continued) Figure 6-7 Flowchart and pseudocode for Dependents report program (continued)

Слайд 15





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
Описание слайда:
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

Слайд 16





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
Описание слайда:
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

Слайд 17





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"
Описание слайда:
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"

Слайд 18





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]
Описание слайда:
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]

Слайд 19





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
Описание слайда:
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

Слайд 20


Programming Logic and Design Seventh Edition, слайд №20
Описание слайда:

Слайд 21


Programming Logic and Design Seventh Edition, слайд №21
Описание слайда:

Слайд 22


Programming Logic and Design Seventh Edition, слайд №22
Описание слайда:

Слайд 23





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
Описание слайда:
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

Слайд 24





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
Each element in one array is associated with an element in the same relative position in the other array
Look through the valid item array for the customer’s item
When a match is found, get the price from the item price array
Описание слайда:
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 Each element in one array is associated with an element in the same relative position in the other array Look through the valid item array for the customer’s item When a match is found, get the price from the item price array

Слайд 25





Using Parallel Arrays (continued)
Описание слайда:
Using Parallel Arrays (continued)

Слайд 26





Using Parallel Arrays (continued)
Use parallel arrays
Two or more arrays contain related data
A subscript relates the arrays
Elements at the same position in each array are logically related
Indirect relationship
Relationship between an item’s number and its price
Parallel arrays are very useful
Описание слайда:
Using Parallel Arrays (continued) Use parallel arrays Two or more arrays contain related data A subscript relates the arrays Elements at the same position in each array are logically related Indirect relationship Relationship between an item’s number and its price Parallel arrays are very useful

Слайд 27


Programming Logic and Design Seventh Edition, слайд №27
Описание слайда:

Слайд 28


Programming Logic and Design Seventh Edition, слайд №28
Описание слайда:

Слайд 29


Programming Logic and Design Seventh Edition, слайд №29
Описание слайда:

Слайд 30





Improving Search Efficiency
The program should stop searching the array when a match is found 
Set a variable to a specific value instead of letting normal processing set it
Improves efficiency
The larger the array, the better the improvement by doing an early exit
Описание слайда:
Improving Search Efficiency The program should stop searching the array when a match is found Set a variable to a specific value instead of letting normal processing set it Improves efficiency The larger the array, the better the improvement by doing an early exit

Слайд 31


Programming Logic and Design Seventh Edition, слайд №31
Описание слайда:

Слайд 32





Improving Search Efficiency (continued)
Описание слайда:
Improving Search Efficiency (continued)

Слайд 33





Searching an Array for 
a Range Match
Programmers may want to work with ranges of values in arrays, 1 through 5 or 20 through 30
Example: mail-order business
Read the customer order data; determine the discount based on the quantity ordered
First approach
An array with as many elements as each possible order quantity
Store the appropriate discount for each possible order quantity
Описание слайда:
Searching an Array for a Range Match Programmers may want to work with ranges of values in arrays, 1 through 5 or 20 through 30 Example: mail-order business Read the customer order data; determine the discount based on the quantity ordered First approach An array with as many elements as each possible order quantity Store the appropriate discount for each possible order quantity

Слайд 34





Searching an Array for 
a Range Match (continued)
Описание слайда:
Searching an Array for a Range Match (continued)

Слайд 35





Searching an Array for 
a Range Match (continued)
Drawbacks of first approach
Requires a very large array; uses a lot of memory
Stores the same value repeatedly
How do you know when you have enough elements?
Customer can always order more
Better approach
Create four discount array elements for each discount rate
A parallel array with a discount range
Use a loop to make comparisons
Описание слайда:
Searching an Array for a Range Match (continued) Drawbacks of first approach Requires a very large array; uses a lot of memory Stores the same value repeatedly How do you know when you have enough elements? Customer can always order more Better approach Create four discount array elements for each discount rate A parallel array with a discount range Use a loop to make comparisons

Слайд 36





Searching an Array for a Range Match (continued)
Описание слайда:
Searching an Array for a Range Match (continued)

Слайд 37


Programming Logic and Design Seventh Edition, слайд №37
Описание слайда:

Слайд 38





Remaining within Array Bounds
Every array has a finite size
Number of elements in the array
Number of bytes in the array
Arrays are composed of elements of the same data type
Elements of the same data type occupy the same number of bytes in memory
The number of bytes in an array is always a multiple of the number of array elements
Access data using a subscript containing a value that accesses memory occupied by the array
Описание слайда:
Remaining within Array Bounds Every array has a finite size Number of elements in the array Number of bytes in the array Arrays are composed of elements of the same data type Elements of the same data type occupy the same number of bytes in memory The number of bytes in an array is always a multiple of the number of array elements Access data using a subscript containing a value that accesses memory occupied by the array

Слайд 39





Remaining within Array Bounds (continued)
Описание слайда:
Remaining within Array Bounds (continued)

Слайд 40





Remaining within Array Bounds (continued)
Program logic assumes every number entered by the user is valid
When an invalid subscript is used:
Some languages stop execution and issue an error
Other languages access a memory location outside of the array
An invalid array subscript is a logical error
Out of bounds: using a subscript that is not within the acceptable range for the array
The program should prevent bounds errors
Описание слайда:
Remaining within Array Bounds (continued) Program logic assumes every number entered by the user is valid When an invalid subscript is used: Some languages stop execution and issue an error Other languages access a memory location outside of the array An invalid array subscript is a logical error Out of bounds: using a subscript that is not within the acceptable range for the array The program should prevent bounds errors

Слайд 41





Using a for Loop to Process Arrays
for loop: a single statement
Initializes the loop control variable
Compares it to a limit
Alters it
The for loop is especially convenient when working with arrays
To process every element
Must stay within array bounds
Highest usable subscript is one less than the array size
Описание слайда:
Using a for Loop to Process Arrays for loop: a single statement Initializes the loop control variable Compares it to a limit Alters it The for loop is especially convenient when working with arrays To process every element Must stay within array bounds Highest usable subscript is one less than the array size

Слайд 42





Using a for Loop to Process Arrays (continued)
Описание слайда:
Using a for Loop to Process Arrays (continued)

Слайд 43





Using a for Loop to Process Arrays (continued)
Описание слайда:
Using a for Loop to Process Arrays (continued)

Слайд 44





Summary
Array: a named series or list of values in memory
Same data type
Different subscript
Use a variable as a subscript to the array to replace multiple nested decisions
Constants can be used to hold an array’s size
Searching through an array requires
Initializing a subscript
Using a loop to test each element
Setting a flag when a match is found
Описание слайда:
Summary Array: a named series or list of values in memory Same data type Different subscript Use a variable as a subscript to the array to replace multiple nested decisions Constants can be used to hold an array’s size Searching through an array requires Initializing a subscript Using a loop to test each element Setting a flag when a match is found

Слайд 45





Summary (continued)
Parallel arrays: each element in one array is associated with the element in a second array
Elements have the same relative position
For range comparisons, store either the low- or high-end value of each range
Описание слайда:
Summary (continued) Parallel arrays: each element in one array is associated with the element in a second array Elements have the same relative position For range comparisons, store either the low- or high-end value of each range

Слайд 46





Summary (continued)
Access data in an array
Use a subscript containing a value that accesses memory occupied by the array
A subscript is out of bounds if it is not within the defined range of acceptable subscripts
The for loop is a convenient tool for working with arrays
Process each element of an array from beginning to end
Описание слайда:
Summary (continued) Access data in an array Use a subscript containing a value that accesses memory occupied by the array A subscript is out of bounds if it is not within the defined range of acceptable subscripts The for loop is a convenient tool for working with arrays Process each element of an array from beginning to end



Похожие презентации
Mypresentation.ru
Загрузить презентацию