Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Right from the Start with Visual Basic .NET 1/e

Similar presentations


Presentation on theme: "Programming Right from the Start with Visual Basic .NET 1/e"— Presentation transcript:

1 Programming Right from the Start with Visual Basic .NET 1/e
4 Arrays Programming Right from the Start with Visual Basic .NET 1/e

2 Objectives Understand the concept of an array
Be able to declare arrays of various sizes Be able to populate and access the elements in an array

3 Objectives (cont.) Understand how to manipulate and process an array
Consider multiple problems that benefit from an array solution Understand the Bubble Sort algorithm

4 4-1 Arrays An array is a variable that holds a collection of related data values. Each of the values in an array is called an element. Each element in the array is identified by an integer value called its index, which indicates the position of the element in the array.

5 4-1 Arrays (cont.) Most modern programming languages implement zero-based arrays, meaning that array index values begin with 0. The array length is the number of elements in the array. The upper bound of an array is the index of the last element.

6 4-1 Arrays (cont.)

7 Creating an Array In Visual Logic you create, or declare, an array using the Make Array command

8 Accessing Individual Elements of an Array
To access individual array elements, you specify the array name and follow it with an index expression enclosed in parentheses. If you attempt to reference an array with an index value greater than the upper bound of the array, the result will be an out-of-bounds error.

9 When to Use Arrays Arrays are useful…
when you are storing or processing large amounts of related data when information must be stored and processed twice

10 4-2 Above Average Problem (Mutual Funds)
The Problem Jim is a financial analyst with many large investment clients. Each year Jim identifies ten different mutual funds that he shares with his clients for investing. At the end of each year he keeps the funds that performed better than the ten-fund average and replaces the others with new funds.

11 Analysis and Design

12 Analysis and Design (cont.)

13 4-3 Largest Value Problem (Highest GPA)
The Problem The Alpha Beta Gamma fraternity is one of many popular Greek organizations on campus. Every semester, ABΓ recognizes the graduating brother who has the highest GPA. The number of graduates changes from semester to semester.

14 Analysis and Design

15 Analysis and Design (cont.)

16 Analysis and Design (cont.)

17 4-4 Working with Index Values (Two-Week Totals)
The Problem Anthony owns a small business and plans to install new inventory hardware and software during the upcoming year. The installation process will require two weeks. To minimize the disruption that will occur during the migration, Anthony wants to deploy the system during the two weeks that had the lowest consecutive two-week total gross sales during the previous year.

18 Analysis and Design

19 Analysis and Design (cont.)

20 4-5 Simulation (Die Roll)
The Problem A balanced die is equally likely to roll a 1, 2, 3, 4, 5, or 6. If a balanced die is rolled many times, the roll values should be evenly distributed. As the number of rolls increases, the distributions should become closer to one-sixth, or percent. What are the percentages after forty rolls? What are the percentages after four hundred rolls?

21 Analysis and Design

22 Analysis and Design (cont.)

23 4-6 Parallel Arrays (Girl Scout Cookies)
The Problem Every spring you look forward to buying a box of Caramel deLites Girl Scout cookies from your niece, Belinda. Her troop gives an award to the girl who sells the most boxes of cookies each year. They are looking to develop a software solution to assist in determining the annual award winner.

24 Analysis and Design Parallel arrays are two or more arrays whose elements are related by their position in the arrays.

25 Analysis and Design (cont.)

26 Analysis and Design (cont.)

27 Chapter Summary An array is a variable that holds a collection of related data values. Most modern programming languages implement zero-based arrays. To access individual array elements, you specify the array name and follow it with an index expression enclosed in parentheses.

28 Chapter Summary (cont.)
Arrays contain a finite number of elements, each of which is referenced by a unique index. Parallel arrays are two or more arrays whose elements are related by their positions in the arrays. Bubble Sort is a simple sorting technique involving multiple passes through the array.

29 Programming Right from the Start with Visual Basic .NET 1/e
4 Arrays Programming Right from the Start with Visual Basic .NET 1/e


Download ppt "Programming Right from the Start with Visual Basic .NET 1/e"

Similar presentations


Ads by Google