INC 161 , CPE 100 Computer Programming

Slides:



Advertisements
Similar presentations
Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
Advertisements

Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
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.
©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.
Multiple-Subscripted Array
Arrays Chapter 8 page /24/07CS150 Introduction to Computer Science 1 Arrays (8.1)  One variable that can store a group of values of the same.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
For loops, nested loops and scopes Jordi Cortadella Department of Computer Science.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Get Longest Run Index (FR) public int getLongestRunIndex(int []values) { int maxRunStart = -1, maxRunLength = 1; int runStart = 0, runLength = 1; for(int.
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Two-Dimensional Arrays
INC 161 , CPE 100 Computer Programming
INC 161 , CPE 100 Computer Programming
Chapter 6 Arrays in C++ 2nd Semester King Saud University
EGR 2261 Unit 10 Two-dimensional Arrays
Two-Dimensional Arrays
INC 161 , CPE 100 Computer Programming
Two Dimensional Array Mr. Jacobs.
Two-Dimension Arrays Computer Programming 2.
Hassan Khosravi / Geoffrey Tien
Array, Strings and Vectors
Today’s Material Arrays Definition Declaration Initialization
Arrays Declarations CSCI N305
C++ Arrays.
INC 161 , CPE 100 Computer Programming
Two-Dimensional Arrays
Engineering Problem Solving with C++, Etter/Ingber
Python I/O.
INC 161 , CPE 100 Computer Programming
INC 161 , CPE 100 Computer Programming
INC 161 , CPE 100 Computer Programming
EKT150 : Computer Programming
Counting Loops.
Lecture 12 Oct 16, 02.
INC 161 , CPE 100 Computer Programming
Introduction To Programming Information Technology , 1’st Semester
INC 161 , CPE 100 Computer Programming
Multidimensional Arrays
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
MSIS 655 Advanced Business Applications Programming
Multidimensional Arrays
Multidimensional array
Multidimensional Arrays
INC 161 , CPE 100 Computer Programming
Multi-Dimensional Arrays
Dr Tripty Singh Arrays.
Lets Play with arrays Singh Tripty
Functions continued.
Lecture 14 2D Arrays Richard Gesick.
Arrays.
Arrays.
Arrays Imran Rashid CTO at ManiWeber Technologies.
EECE.2160 ECE Application Programming
CSCE 206 Lab Structured Programming in C
Big-O Analysis Example
EECE.2160 ECE Application Programming
Arrays Introduction to Arrays Reading for this Lecture:
Dr. Khizar Hayat Associate Prof. of Computer Science
Presentation transcript:

INC 161 , CPE 100 Computer Programming Lab 6

Array Array is a group of data of the same type. e.g. A group of integers 2 6 3 4 A group of char ‘a’ ‘v’ ‘j’ ‘d’ A group of float 1.2 2.3 7.1 6.5

Array Declaration and Initialization Use [ ] denote array inside is number of data int a[6]; Group of 6 integers Use { } for initialization float b[4] = {2, 5, -4, 6}; Group of 4 floating point numbers with initial values

Array Indexing int a[6]; Index starts from 0 Index can be Constant 0 Variable i Expression i+2

Example 1 Use debugger to investigate. main () { int a[6]; int b[6] = {1,2,3,4,5,6}; int i = 3; a[0] = 100; b[4] = 200; a[i] = 300; a[i+2] = 400; } Use debugger to investigate.

Task 1 Write a program that move all the data from array b to a. Hint: Do it one-by-one

Task 2 Write a flowchart/program that calculate the sum of all numbers in the array b and print the result on the screen. Use a loop.

Task 3 Write a flowchart/program that calculate the average of all numbers in the array and print it out on the screen. Modify from Task 2.

2-Dimensional Array 2 Rows 3 Columns (6 integers) int b[2][3]; Use 2 layers of { } for initialization int b[2][3] = {{2, 5}, {-4, 6}};

2-Dimensional Array Indexing

Example 2 Use debugger to investigate. main () { float a[2][3]; float b[2][3] = {{1,2,3},{4,5,6}}; a[0][0] = 100; a[1][2] = b[0][1]; b[1][0] = 200; } Use debugger to investigate.

Task 4 Write a program that move all the data from array b to a. Hint: Use nested loop