1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.

Slides:



Advertisements
Similar presentations
1.
Advertisements

Arrays. What is an Array? An array is a way to structure multiple pieces of data of the same type and have them readily available for multiple operations.
 “Regular” variable ◦ Holds a single value ◦ For example Dim Student1 as String Dim Student2 as String Dim Student3 as String … Dim Studentn as String.
VBA Modules, Functions, Variables, and Constants
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
Arrays.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
Chapter 8 Arrays and Strings
Chapter 7: Working with Arrays
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
User-defined Data Types VB provides programmers with the ability to create user-defined types. User-defined Types are collections of related variables.
VB .NET Programming Fundamentals
Multidimensional Arrays C++ also allows an array to have more than one dimension. For example, a two-dimensional array consists of a certain number of.
ISAT 252 Introduction to Arrays. Should have read 2 Chapter 8 –pp , and pp
M1G Introduction to Programming 2 4. Enhancing a class:Room.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
IE 212: Computational Methods for Industrial Engineering
1 Microsoft Visual Basic 2010 Arrays. 2 Using a One-Dimensional Array Lesson A Objectives After completing this lesson, you will be able to:  Declare.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Chapter 9: Advanced Array Concepts
Using Arrays and File Handling
Chapter 8 Arrays Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
CIS162AD - C# Arrays – part 1 12_arrays_loading.ppt.
Arrays Chapter 8. Chapter 8 - Part 12 Variable and Variable Array Variable Stores only one value Variable Array Variable that has 1 symbolic name but.
Spreadsheet Models for Managers: Session 14 14/1 Copyright © Richard Brenner Spreadsheet Models for Managers Session 14 Using Macros II Function.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley More About Array Processing 8.2 There Are Many Uses of Arrays and Many Programming.
Tutorial 101 Variable Arrays A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
Arrays Chapter 8. Overview u General discussion u Variable arrays u Control arrays u Multi-dimensional variable arrays  Two-dimensional  Three-dimensional.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
Collections 1. Two Hierarchies Recall that the architecture of an object- oriented program consists of two hierarchies: – The Class Structure (“is a”)
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Lab 5 Arrays ► Lab 4 Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
Programming Right from the Start with Visual Basic .NET 1/e
VBA - Excel VBA is Visual Basic for Applications
Introduction to Programming Lecture 5
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Visual Basic .NET BASICS
Tutorial 11 Arrays Tutorial 11: Arrays.
CIS16 Application Development and Programming using Visual Basic.net
Presentation transcript:

1 Working with Data Structures Kashef Mughal

2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common Language Runtime) - compiles the code written in all the.NET languages  Bottom line - With.NET Microsoft wants to compete with other Object Oriented languages like JAVA, C++

3 Arrays  An array is a group of variables that have the same name and data type and are related in some way  Array is really a list that holds similar data e.g. employee lastnames  Although arrays in Visual Basic.NET can have as many as 60 dimensions, the most commonly used arrays are one-dimensional and two-dimensional  Programmers use arrays to store related data in the internal memory of the computer

4 One-Dimensional Arrays  A one-dimensional array is simply a row (or column) of variables  A two-dimensional array resembles a table in that it has rows and columns  Each element in an array is identified by a subscript or index, which Visual Basic.NET assigns to the variable when the array is created  You refer to an array element by the array’s name followed by the element’s index

5 One-Dimensional Array AlaskaMontanaSouth CarolinaTennesseeTexas Alaska Montana South Carolina Tennessee Texas

6 Declaring an Array  Basic Syntax  accessibility arrayname() As datatype = {initialValues}  accessibility is Dim, Public, or Private  These statements create and initialize the array variables in memory  In VB.NET arrays are zero based meaning the first item in the array has a 0 index

7 Declaring an array - Examples  Dim strCitys(3) As String  Private intNumbers(5) As Integer  Private udtItems(4) As ItemStruc  Private strStates() As String = {“Hawaii”, “Alaska”, “Maine”}  Dim intScores() As Integer = {75, 9, 23, 6}

8 Storing Data in a an Array  You can use a variety of ways to enter data into an array strMonthArray(0) = “Jan” strMonthArray(1) = “Feb” strMonthArray(2) = “Mar” strMonthArray(3) = “Apr” strMonthArray(4) = “May” strMonthArray(5) = “June ”

9 Display the Contents of a an Array  You can use For.. Next loop to display an Array or to search for a value Dim strMonths() As String = {“JAN”, “FEB”, “MAR”, “APR”, “MAY”, “JUN”} Dim intX As Integer For intX = 0 To strMonths.Length - 1 Me.MonthListBox.Items.Add(strMonths(intX)) Next intX

10 Array Properties and Methods ClearSets a range of elements in the Array to zero or to a null reference (Nothing in Visual Basic). CopyCopies a section of one Array to another Array LengthReturns the size of the array UBoundReturns the upper bound (index) for the given array. Also GetUpperBound is the same LBoundReturns the lower bound (index) for the given array. Also GetLowerBound is the same SortSorts the elements in Array

11 In-class Assignments  Try the following Exercises  Pages  Pages  Page  Page 260  Page 263  Take a break when done

12 Misc. Array Topics  The ReDim statement is used to change the size of one or more dimensions of an array that has already been formally declared  The ReDim statement can appear only at procedure level. This means you can redefine arrays inside a procedure but not at class or module level.  Use the Preserve keyword with the ReDim to save the contents of existing array

13 Two-Dimensional Arrays  A two-dimensional array resembles a table in that the variables are in rows and columns AC24ShirtRed BD12CoatBlue CP14BlouseWhite strProducts(0, 0)strProducts(0, 2) strProducts(2, 1) strProducts(1, 2)

14 How would you initialize a Two-Dimensional Array  Lets say we are working with an array that is 4*2. We could use the following code to initialize the values  We are using next For.. Loops here dim intRow, intColumn as integer dim intScores For intRow = 0 To 3 For intColumn = 0 To 1 intScores(intRow, intColumn) = 0 Next intColumn Next intRow

15 Other Data Structures  Constants  Enumerations  Structures  ArrayList  Collections  Hashtable

16 Constants  Constants store values that, as the name implies, remain constant throughout the execution of an application.  Using constants allows you to provide meaningful names instead of numbers, making your code more readable.  Examples of constants are values like Pi, location of a file that does not change  Public Const pi As Single = 3.14

17 Enumerations  Enumerations provide a convenient way to work with sets of related constants  In addition they let you associate constant values with names.  For example, you can declare an enumeration for a set of integer constants associated with the days of the week, and then use the names of the days rather than their integer values in your code  The only data types allowed are integer, long, short and byte

18 Structure  You can combine data items of different types to create a structure.  A structure associates one or more members with each other and with the structure itself.  When you declare a structure, it becomes a composite data type, and you can declare variables of that type.  Structures are useful when you want a single variable to hold several related pieces of information. E.g. you might want to keep an employee's name, telephone extension, and salary together

19 In-class Assignments  Try the following Exercises  Pages  Pages  Page 234  Page 236  Pages  Take a break when done

20 ArrayList  ArrayList is a form of an array that is easier to use  Think of an ArrayList as a resizable one- dimensional array of objects.  In addition to automatic resizing, ArrayList has a few other advantages over Array.  ArrayList has methods that will add, insert, and remove a range of elements  ArrayList does not need the index like an array does

21 Collections  Collection object gives you a way to refer to a related group of items as a single object.  Collections are used a lot by VB itself (components in a project, for example, are a collection) and are pretty flexible.  The members in a collection don't even have to be the same data type

22 Hashtable  Hashtable is a special kind of collection  The Hashtable collection type stores key-value pairs and allows you to locate items in the collection based on the key  Similar in principle to a primary key in a database table  The advantage is that we do not need an index to locate the item

23 Midterm  On 2/11  Chapter 1-7  In-class material  Closed Book  100 questions  true/false  multiple choice  200 points  2 hours  Grades right now

24 In-class Assignments  Try the following Exercises  Page 247  Page 248  Page 251  Page 254  Next week Chapter 7 and Review