1 st Semester 2005 1 Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.

Slides:



Advertisements
Similar presentations
1 Arrays, Strings and Collections [1] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
Advertisements

Introduction to Java 2 Programming Lecture 5 Array and Collections.
Copyright © 2002 Pearson Education, Inc. Slide 1.
C Language.
Arrays I Savitch Chapter 6.1: Introduction to Arrays.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
1 2-D Arrays Overview l Why do we need Multi-dimensional array l 2-D array declaration l Accessing elements of a 2-D array l Declaration using Initializer.
Multidimensional Arrays in Java Vidhu S. Kapadia.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Arrays. A group of data with same type stored under one variable. It is assumed that elements in that group are ordered in series. In C# language arrays.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
C programming---Arrays scalar: capable of holding a single data item aggregate variables: capable of holding a collections of values. Two kinds of aggregates.
Multi-Dimensional Arrays in Java "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger.
Java Unit 9: Arrays Declaring and Processing Arrays.
French Territory of St. Pierre CSE 114 – Computer Science I Arrays.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
JAVA Arrays. Objectives Be able to declare and initialize arrays Be able to conceptualize (draw) how arrays are represented in computer memory. Be able.
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.
1 Chapter 8 Multi-Dimensional Arrays. 2 1-Dimentional and 2-Dimentional Arrays In the previous chapter we used 1-dimensional arrays to model linear collections.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Programming Fundamentals I (COSC-1336), Lecture 8 (prepared after Chapter 7 of Liang’s 2011 textbook) Stefan Andrei 4/23/2017 COSC-1336, Lecture 8.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
1 nd Semester Module7 Arrays Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Chapter overview This chapter focuses on Array declaration and use Bounds checking and capacity Arrays storing object references Variable length parameter.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Section 3 - Arrays and Methods. Arrays Array: collection of group of data variables of same type, sharing the same name for convenience - Easy to search.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
PHY281 Scientific Java Programming ArraysSlide 1 Arrays In this section we will learn how about storing groups of related variables that share the same.
C# E1 CSC 298 Arrays in C#. C# E2 1D arrays  A collection of objects of the same type  array of integers of size 10 int[] a = new int[10];  The size.
Arrays.
1 st Semester Module 6 C# Methods – Part II อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 nd Semester Module2 C# Basic Concept Thanawin Rakthanmanon Computer Engineering Department Kasetsart University, Bangkok.
Multidimensional Arrays Computer and Programming.
1 st Semester Module11 Struct Type in C# Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
 Introducing Arrays  Declaring Array Variables, Creating Arrays, and Initializing Arrays  Copying Arrays  Multidimensional Arrays  Search and Sorting.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Chapter 9 Introduction to Arrays Fundamentals of Java.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Arrays and Collections
Two-Dimensional Arrays
C# Arrays.
Two-Dimension Arrays Computer Programming 2.
Arrays Computer & Programming Group
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
Introduction To Programming Information Technology , 1’st Semester
Multidimensional Arrays
Cs212: Data Structures Computer Science Department Lecture 2: Arrays.
Thanachat Thanomkulabut
Module5 Looping Techniques: Part 2
Module5 Looping Techniques: Part 2
Module8 Multi-dimensional Array
Module 8 & 9 Method :Part I & Array :Part II
Arrays in Java.
Thanachat Thanomkulabut
Presentation transcript:

1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department Kasetsart University, Bangkok THAILAND

1 st Semester /25 Outlines  C# Review  Array Overview  Array Usage  Examples

1 st Semester /25 C# Structure – Multiple MethodsNamespace Class Main() Method1() Method2() Method3() MethodNN()

1 st Semester /25 Method Declaration static ( ) { ; } #remark return-type can be - data type = int, double, string, … need return statement need return statement - void = return no value

1 st Semester /25 Outlines  C# Review  Array Overview  Array Usage  Examples

1 st Semester /25 What is Array? “An array is an indexed collection of objects, all of the same type”

1 st Semester /25 Why Array?  We want to store all the midterm scores of all students in a class with 60 students. int s1, s2, s3, s4, s5; int s6, s7, s8, s9, s10; int s11, s12, s13, s14, s15; int s16, s17, s18, s19, s20;... int s56, s57, s58, s59, s60; Declaration without Array int [] s = new int[60]; Declaration with Array

1 st Semester /25 Array make our life easier  We want to find the mean of the scores. int total=0, mean; total = s1 + s2 + s3 + … + s60; mean = total / 60; Coding without Array int total=0, mean; for (int i = 0; i<60; i++) total = total + s[i]; total = total + s[i]; mean = total / 1000; Coding with Array

1 st Semester /25 Outlines  C# Review  Array Overview  Array Usage  Examples

1 st Semester /25 ARRAY  One Dimensional Array  Multi-dimensional Array

1 st Semester /25 Array Declaration   Syntax: Declaration only Declaration with creation Declaration with initialization: 2 ways [] ; [] = new [ ]; [] = { }; 2 [] = new [ ] { }; 1

1 st Semester /25 Array Declaration Example  int [] ai;  int [] ai = new int[5];  int [] ai = new int[5] {1, 2, 3, 4, 5};  int [] ai = {1, 2, 3, 4};

1 st Semester /25 score 5679 score More examples int [] score = new int[6]; int [] score = new int[4] {5, 6, 7, 9}; 102 3

1 st Semester /25 Accessing Array Elements  Supply an integer index for accessing array elements  indexes are zero-based int [] score = new int[4]; 1023score score[0] = -1; score[3] = 5; Console.WriteLine(score[3]); 5

1 st Semester /25 How to find Array’s length?  By property Length   By method GetLength() int [] matrix = new int[5]; Console.WriteLine(matrix.Length); int [] matrix = new int[5]; Console.WriteLine(matrix.GetLength(0));

1 st Semester /25 foreach statement int [] matrix = new int[5]; …… Accessing matrix with for loop for (int i=0; i<5; i++) Console.WriteLine(matrix[i]); Console.WriteLine(matrix[i]); Accessing matrix with foreach loop foreach (int s in matrix) Console.WriteLine(s); Console.WriteLine(s);

1 st Semester /25 Break 5 Minutes

1 st Semester /25 ARRAY  One Dimensional Array  Multi-dimensional Array

1 st Semester /25 Multi-dimensional Arrays Declaration   Syntax: [,] ; [,,] ;   Creation: = new [, ]; 2 dimensions 3 dimensions 2 dimensions

1 st Semester /25 Array Declaration Example  int [, ] grid2; grid2 = new int [3,2];  int [,, ] grid3; grid3 = new int [3, 2, 4];

1 st Semester /25 More examples new int[2, 3] grid[1,1] == ? grid.GetLength(0) == ? grid.GetLength(1) == ? grid.Length == ?

1 st Semester /25 How to find Array’s #dimension?  By property Rank int [] matrix = new int[5]; Console.WriteLine(matrix.Rank); int [,,] matrix = new int[5,2,3]; Console.WriteLine(matrix.Rank); int [,] matrix = new int[5,2]; Console.WriteLine(matrix.Rank);

1 st Semester /25 Outlines  C# Review  Array Overview  Array Usage  Examples

1 st Semester /25 Example 1  Write program for find result of matrix A + matrix B #matrix size = 3x3

1 st Semester /25 Example 2  Write program for converting number in base 10 to base 16

1 st Semester /25 Example 3  Write a program for calculating summation of 100 student's scores