Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.

Slides:



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

Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
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.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
Simple Arrays COMP104 Lecture 11 / Slide 2 Arrays * An array is a collection of data elements that are of the same type (e.g., a collection of integers,characters,
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
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.
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
Simple Arrays Programming COMP104 Lecture 12 / Slide 2 Arrays l An array is a collection of data elements that are of the same type (e.g., a collection.
Arrays.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Array, Structure and Union
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Structured Data Types struct class Structured Data Types array – homogeneous container collections of only one type struct – heterogeneous data type.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
Arrays.
Arrays Chapter 12. Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays.
Struct s (7.4) Used as data aggregates for an entity can be different types of data e.g. for student id, name, GPA, address,... Similar to classes, but.
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Lecture 2 Arrays. Topics 1 Arrays hold Multiple Values 2 Accessing Array Elements 3 Inputting and Displaying Array Contents 4 Array Initialization 5 Using.
1 Principles of Computer Science I Honors Section Note Set 3 CSE 1341.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Chapter 6 Arrays in C++ 2nd Semester King Saud University
EGR 2261 Unit 10 Two-dimensional Arrays
CO1401 Program Design and Implementation
Arrays Low level collections.
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.
Pointers & Arrays.
Chapter 7 – Arrays.
Computer Programming BCT 1113
Two Dimensional Array Mr. Jacobs.
Sorting Algorithms.
Arrays Part-1 Armen Keshishian.
New Structure Recall “average.cpp” program
C++ Arrays.
Parallel Arrays Parallel array =>Two or more arrays with the same number of elements used for storing related information about a collection of data. Example:
A solution to a list of records
Chapter 9: Pointers.
Repetition Statements
Visual Basic .NET BASICS
What’s Left in the Course
Previous Lecture Review
Arrays November 8, 2017.
Review for Final Exam.
Strings A collection of characters taken as a set:
Text Files All the programs you've seen so far have one thing in common: Any data the program uses or calculates is lost when the program ends. In order.
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.
Review for Final Exam.
CS150 Introduction to Computer Science 1
Arrays in Java.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
C++ winter2008(by:J.Razjouyan)
Fundamental Programming
Pointers & 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.
CS150 Introduction to Computer Science 1
Programming Fundamental
Arrays Introduction to Arrays Reading for this Lecture:
Arrays Prepared By Paritosh Srivastava PGT (CS) KV NHPC Banbasa.
§ § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊
Structures, Unions, and Enumerations
Presentation transcript:

Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the array, and is distinguished from the other elements by using an index number (or subscript). An element of an array is just like a regular variable of the same type.

Declaring Arrays Basic Declaration: int values[10]; double rates[5]; char lastName[21]; Declaring and Initializing the Elements int nums[7] = { 22, 56, 38, 14, 0, 1854, 971 }; char lastName[6] = {'W', 'e', 'i', 'n', 'e', 'r'}; double temps[4] = ( 22.7, 165.888, -300, 3.14159 };

Declaring Arrays Special Declaring and Initializing int nums[] = { 22, 56, 38, 14 }; char name[] = {‘W’, ‘e’, ‘i’, ‘n’, ‘e’, ‘r’}; double values[10] = { 14.7, 22.865, 117.888 }; double values[10] = { 0 }; You can't declare with empty braces if you don't have an initialization list. When you declare more elements than you have values in the initialization list, all other elements are initialized to a zero value.

cout << "The value is: " << values[5] << endl; int values[8] = { 22, 786, 13, 44, 0, -121, 98, 1432 }; values[0] = 55; cout << "The value is: " << values[5] << endl; values[7]++; values[0] += values[1]; cin >> values[1]; Anything I can do to an int variable, I can do to an element of an int array.

values[count * 2] = values[1]; int values[8] = { 22, 786, 13, 44, 0, -121, 98, 1432 }; int count = 3; values[count] = 17; values[count + 1] = 186; values[count * 2] = values[1]; for( count = 0; count < 8; count++ ) values[count] += 6; for( count = 0; count < 8; count += 2 ) values[count] *= values[count]; The most powerful aspect of arrays is that you can specify an element with a variable or an expression. Process different elements of an array in a loop. NEXT: Standard applications of arrays array_total.cpp array_highest.cpp array_count.cpp array_find.cpp array_overrun.cpp

Using Parallel Arrays Two or more arrays where the same elements of each array are related to each other. For example, one array is a list of employee ID's. Another array is a list of the number of hours that each person worked. Element 0 of the first array identifies an employee. Element 0 of the second array is the number of hours that employee worked. Search the first array for a particular employee. When found, the same element number in the second array is the number of hours (s)he worked. Draw it on the board. array_parallel.cpp

Using Parallel Arrays ids hours 1 2 3 4 5 1111 1 2 3 4 5 43.25 2323 1 2 3 4 5 1111 1 2 3 4 5 43.25 2323 37.5 1781 40.0 6775 45.5 3217 22.75 4002 37.5