Engr 0012 (04-1) LecNotes 25-01.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Introduction to C Programming
Engr 0012 (04-1) LecNotes Engr 0012 (04-1) LecNotes arrays collection of values - all of the same type, e.g., int individual values referred.
Arrays. Topics Tables of Data Arrays – Single Dimensional Parsing a String into Multiple Tokens Arrays - Multi-dimensional.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
1 More on Arrays Passing arrays to or from methods Arrays of objects Command line arguments Variable length parameter lists Two dimensional arrays Reading.
1 Arrays In many cases we need a group of nearly identical variables. Example: make one variable for the grade of each student in the class This results.
Multiple-Subscripted Array
1 CS 201 Array Debzani Deb. 2 Having trouble linking math.h? Link with the following option gcc –lm –o test test.o.
1 Arrays & functions Each element of an array acts just like an ordinary variable: Like any ordinary variable, you can pass a single array element to a.
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: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
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.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Defining a 2d Array A 2d array implements a MATRIX. Example: #define NUMROWS 5 #define NUMCOLS 10 int arr[NUMROWS][NUMCOLS];
Chapter 7 Arrays. Introductions Declare 1 variable to store a test score of 1 student. int score; Declare 2 variables to store a test score of 2 students.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Arrays Version 1.1. Topics Tables of Data Arrays – Single Dimensional Parsing a String into Multiple Tokens Arrays - Multi-dimensional.
Arrays.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
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.
CSI 3125, Preliminaries, page 1 Arrays. CSI 3125, Preliminaries, page 2 Arrays Group of related typed variables that referred to a common name Each data.
Arrays Chapter 12. One-Dimensional Arrays If you wanted to read in 1000 ints and print them in reverse order, it would take a program that’s over 3000.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
Lecture 9 – Array (Part 2) FTMK, UTeM – Sem /2014.
Arrays – two dimensional Chapter 14 This chapter explains how to do the following with a two dimensional array: Declare, use indices, obtain size, pass.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
1 Multidimensional Arrays Chapter 13 2 The plural of mongoose starts with a "p" Initializing a multidimensional array Processing by.
Arrays float Scores[9]; ? index: element // one dimensional array 2.
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.
Arrays in C. What is Array? The variables we have used so far can store a single value. Array is a new type of variable capable of storing many values.
Strings C supports strings using one-dimensional character arrays. A string is defined as a null-terminated character array. In C, a null is 0. You must.
Arrays 4/4 By Pius Nyaanga. Outline Multidimensional Arrays Two-Dimensional Array as an Array of Arrays Using the length Instance Variable Multidimensional.
Introduction to Programming
Arrays.
EGR 2261 Unit 10 Two-dimensional Arrays
Lecture 8: 2D Arrays and Nested Loops
Two-Dimensional Arrays
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
Computer Programming BCT 1113
Two Dimensional Arrays
Two Dimensional Array Mr. Jacobs.
© 2016 Pearson Education, Ltd. All rights reserved.
Programming Fundamental
Numeric Arrays Numeric Arrays Chapter 4.
CS 1430: Programming in C++.
Chapter-7 part3 Arrays Two-Dimensional Arrays The ArrayList Class.
C-Programming, continued
C Passing arrays to a Function
Arrays … The Sequel Applications and Extensions
Engineering Problem Solving with C++, Etter/Ingber
Multidimensional Arrays
Chapter 8 Slides from GaddisText
JavaScript Arrays.
Multidimensional Arrays
Chapter 7 Part 2 Edited by JJ Shepherd
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
Multidimensional array
Multidimensional Arrays
Multi-Dimensional Arrays
Multi-Dimensional Arrays
EECE.2160 ECE Application Programming
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
Assignment due Write a program the generates a random integer expression, presents the two operands and the result to the user, and asks the user to tell.
Multidimensional Arrays Section 6.4
C++ Array 1.
Presentation transcript:

Engr 0012 (04-1) LecNotes 25-01

Arrays - review Declaring an array use defined constant to specify maximum number of elements in the array // preprocessor commands #define MAXARRAYSIZE 100   … main() {  // variable declaration double length[MAXARRAYSIZE], // array of lengths width[MAXARRAYSIZE]; // array of widths int actualsize, // actual amt in use i; // loop index type of values meaningful name maximum number of elements in [ ] arrays do not need to be “full” - need to keep track of how much is actually used Engr 0012 (04-1) LecNotes 25-02

Arrays Memory management compiler remembers only location (address of) first location &length[0]  length &length[0] &length[MAXARRAYSIZE-1] … declaration sets aside MAXARRAYSIZE memory locations capable of holding specified type of information &length[actualsize-1] do not need to use entire allocation of memory ==> need to keep track of actualsize Engr 0012 (04-1) LecNotes 25-03

Arrays Using arrays … &length[0] &length[MAXARRAYSIZE-1] &length[actualsize-1] length[0] length[18] length[8] length[-2] length[260] accessing values - name and index Engr 0012 (04-1) LecNotes 25-04

Two dimensional arrays - tables/matrices N rows 1.200 3.412 5.321 21.872 -16.322 -23.333 16.098 0.987 9.765 2.908 -0.888 312.099 222.987 16.999 87.434 -8.909 54.669 322.419 -435.666 -87.554 0.988 16.234 -76.287 12.359 M columns Dimension: NxM (rows x columns) if N = M (i.e., dimension NxN) square matrix still require all values be of same type Engr 0012 (04-1) LecNotes 25-05

Two dimensional arrays - declaring use defined constants to declare dimensions // preprocessor commands #define MAXROW 10 #define MAXCOL 10   … main() {  // variable declaration double length[MAXROW][MAXCOL]; // table of lengths int actrows, // actual rows in use actcol, // actual col in use i,j,k; // loop indices #define MAX2D 10 if square matrix, only need one size specify rows and columns double length[MAX2D][MAX2D]; // table of lengths keep track of amount in use Engr 0012 (04-1) LecNotes 25-06

Two dimensional arrays - using length[1][2] value in 2nd row, 3rd column &length[6][4] address of value in 7th row, 5th column &length[0][0]  length address of first element Engr 0012 (04-1) LecNotes 25-07

[ ] tells that the variable is an array Arrays - function prototypes/parameter lists // preprocessor commands #define MAXARRAYSIZE 100   … main() {  // variable declaration double length[MAXARRAYSIZE], // array of lengths width[MAXARRAYSIZE]; // array of widths int actualsize, // actual amt in use i; // loop index [ ] tells that the variable is an array // function prototypes int getarray( double length[ ] ); double avearray( double length[ ], int actsize );   used to return number of values actually in use need to send amount actually in use Engr 0012 (04-1) LecNotes 25-08

Arrays - calling statements/parameter lists // preprocessor commands #define MAXARRAYSIZE 100 // function prototypes int getarray( double length[ ] ); double avearray( double length[ ], int actsize );   … main() {  // variable declaration double length[MAXARRAYSIZE], // array of lengths width[MAXARRAYSIZE]; // array of widths int actualsize, // actual amt in use i; // loop index name w/o [ ] // calling statement actualsize = getarray( length ); ave = avearray( length, actualsize )  ==> sending address of first element Engr 0012 (04-1) LecNotes 25-09

2D arrays - function prototypes/parameter lists // preprocessor commands #define MAX1D 100 #define MAX2D 100   … main() {  // variable declaration double oned[MAX1D]; // 1D array double twod[MAX2D][MAX2D]; // 2D array int onedact, // 1D array in use actrows, // actual amt in use i,j,k; // loop indices  need to send amount in use // function prototypes void fill( double onedarray[], int used1D, double twodarray[][MAX2D], int used2D );   need to specify maximum number of columns Engr 0012 (04-1) LecNotes 25-10

2D arrays - calling statements/parameter lists // preprocessor commands #define MAX1D 100 #define MAX2D 100   … main() {  // variable declaration double oned[MAX1D]; // 1D array double twod[MAX2D][MAX2D]; // 2D array int onedact, // 1D array in use actrows, // actual amt in use i,j,k; // loop indices  // function prototypes void fill( double onedarray[], int used1D, double twodarray[][MAX2D], int used2D );   // calling statement fill( oned, onedact, twod, actrows ); local array name w/o [] ==> sending address Engr 0012 (04-1) LecNotes 25-11