Lecture Set 9 Arrays, Collections and Repetition Part C - Random Numbers Rectangular and Jagged arrays.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Arrays.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
Multidimensional Arrays in Java Vidhu S. Kapadia.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
Chapter 9: Arrays and Strings
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
CS305j Introduction to Computing Two Dimensional Arrays 1 Topic 22 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
IE 212: Computational Methods for Industrial Engineering
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
Chapter 8 Arrays and Strings
Session 7 JavaScript/Jscript: Arrays Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
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.
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.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
 Pearson Education, Inc. All rights reserved Arrays.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
 Pearson Education, Inc. All rights reserved Arrays.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 7 Arrays. A 12-element array Declaring and Creating Arrays Arrays are objects that occupy memory Created dynamically with keyword new int c[]
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Topic 26 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable.
Lecture 7 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
+ Arrays & Random number generator. + Introduction In addition to arrays and structures, C supports creation and manipulation of the following data structures:
1D Arrays and Random Numbers Artem A. Lenskiy, PhD May 26, 2014.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays in Classes and Methods l Programming.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
IT259 Foundation of Programming Using Java Unit 9 Seminar : (Chapter 8 ) Instructor : Vladimir Gubanov, PhD
Arrays.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Arrays Chapter 7. 2 Declaring and Creating Arrays Recall that an array is a collection of elements all of the _____________ Array objects in Java must.
ONE DIMENSIONAL ARRAYS AND RANDOM NUMBERS. Introduction In addition to arrays and structures, C supports creation and manipulation of the following data.
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
 2005 Pearson Education, Inc. All rights reserved Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Two-Dimensional Arrays
Computer Programming BCT 1113
IS 350 Arrays.
Arrays, Collections and Repetition Part A – Arrays and Repetition
Presentation transcript:

Lecture Set 9 Arrays, Collections and Repetition Part C - Random Numbers Rectangular and Jagged arrays

Slide 2 Objectives Understand the concept of random numbers and how to generate random numbers Understand how to declare and manipulate rectangular and higher dimension arrays Understand how to declare and manipulate jagged arrays Working with arrays of objects 8/18/2013 1:06 PM

Slide 3 Introduction to Random Numbers Applications that require random numbers Gaming and casino applications Computer simulations Test data generation The process of creating a sequence of random numbers is called random number generation 8/18/2013 1:06 PM

Slide 4 Operation of a Random Number Generator A random number generator is initialized based on a seed value Given the same seed value, the same random number sequence will be generated Different seed values will generate different random sequences The time of day (often expressed in milliseconds) is often used to create random seed values 8/18/2013 1:06 PM

Slide 5 The System.Random Class The System.Random class of the FCL is used to create a random number generator and generate and get random values We can generate integer and double random values The constructor of the System.Random class creates the random number generator (an instance of the random class) Using no constructor arguments, a random seed value is used The seed value is based on the time of day Random rndVal = new Random(); This is the same as Random rndVal = new Random(DateTime.Now.Millisecond); 8/18/2013 1:06 PM

Slide 6 The Next Method Without arguments, the Next method gets a positive random Integer value Random rndValR = new Random;; int rndValI = rndValR.Next(); With two arguments, a value within a range is returned The first argument contains the lower bound and the second argument contains the upper bound rndValI = rndValR.Next(1, 10); rndValI = rndValR.Next(1, 6); // Let index be an integer index = rndValR.Next(0, myDictionaryWords.Length - 1); The second line could be used to generate the value of the roll of a single die. How would you generate a random value representing the roll of two dice? 8/18/2013 1:06 PM

Slide 7 The NextDouble Method The NextDouble method returns a random value between 0.0 and 1.0 The value is in the interval [0.0<=value<1.0) Closed on the left and open on the right Example: double randomDouble; randomDouble = _ rndValR.NextDouble() ‘A value such a is generated 8/18/2013 1:06 PM

Slide 8 Introduction to Two-dimensional Arrays A two-dimensional array has rows and columns Conceptually, it's similar to a grid or table Two-dimensional arrays have two subscripts instead of one Declare a two-dimensional array with unspecified dimensions int [,] Table; Declare a two-dimensional array with 10 rows and 10 columns int [9, 9] Table; 8/18/2013 1:06 PM

Slide 9 Initializing Two-dimensional Arrays Two-dimensional arrays can be initialized just as one- dimensional arrays can be initialized The array must not be given an initial size The initialization list is nested as follows: int SalesArray[,] = { {150, 140, 170, 178}, {155, 148, 182, 190}, {162, 153, 191, 184}, {181, 176, 201, 203} }; 8/18/2013 1:06 PM

Slide 10 Referencing Elements in a Two-dimensional Array Two-dimensional arrays require two subscripts instead of one A comma separates the two subscripts Reference the first row and column in the array named SalesArray int cell; cell = SalesArray[0, 0]; 8/18/2013 1:06 PM

Slide 11 Introduction to Three-dimensional Arrays (optional) It's possible to create arrays with three dimensions A three-dimensional array has three subscripts instead of two Declare a dynamic three-dimensional array int cube[,,]; Declare a 10 by 10 by 10 array (1000 elements) double cube[10, 10, 10]; 8/18/2013 1:06 PM

Slide 12 Working with Arrays of Objects Arrays can store object references in addition to storing primary data types Example to store text box references: textbox [3] textBoxList; textBoxList[0] = txtFirstName; textBoxList[1] = txtLastName; textBoxList[2] = txtAddress; What does this array look like? 8/18/2013 1:06 PM

Slide 13 Memory Allocation to Store an Array of Text Boxes (VB) 8/18/2013 1:06 PM

Slide 14 Another View of 2D (Rectangular) Arrays 8/18/2013 1:06 PM

Slide 15 Operations on a 2-Dimension Array 8/18/2013 1:06 PM

Slide 16 More Operations on a 2-Dimension Array 8/18/2013 1:06 PM

Slide 17 Jagged Arrays (by Example) 8/18/2013 1:06 PM

Slide 18 Jagged Array References (optional) I am not sure you will have occasion to do this – but maybe The example is interesting from a pedagogic view It illustrates memory allocation issues discussed already 8/18/2013 1:06 PM

Slide 19 More Jagged Array (examples – optional) 8/18/2013 1:06 PM

Slide 20 Yet ANOTHER Example (optional) 8/18/2013 1:06 PM

Slide 21 8/18/2013 1:06 PM

Slide 22 8/18/2013 1:06 PM