Introduction to Programming with C++ Fourth Edition

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

1.
Chapter 7: Arrays In this chapter, you will learn about
Arrays.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Programming with Microsoft Visual Basic 2005, Third Edition
An Introduction to Programming with C++ Fifth Edition
Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
Arrays.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Chapter 9: Arrays and Strings
Chapter 9: Arrays and Strings
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
Chapter 9 Introduction to Arrays
Programming Logic and Design Fourth Edition, Comprehensive
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
11 Chapter 8 ARRAYS Continued. 22 MULTI-DIMENSIONAL ARRAYS A one-dimensional array is useful for storing/processing a list of values. For example: –The.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
1 Microsoft Visual Basic 2010 Arrays. 2 Using a One-Dimensional Array Lesson A Objectives After completing this lesson, you will be able to:  Declare.
Chapter 9: Advanced Array Concepts
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
 2006 Pearson Education, Inc. All rights reserved Arrays.
A First Book of ANSI C Fourth Edition
Chapter 8 Arrays and Strings
Chapter 7 One-Dimensional Arrays 7.1 Arrays in C One of the more useful features of C is the ability to create arrays for storing a collection of related.
Array Processing.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
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 
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.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 12 Manipulating Larger Quantities of Data.
Chapter 6: Arrays: Lists and Tables
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
1 Topic: Array Topic: Array. 2 Arrays Arrays In this chapter, we will : Learn about arrays Learn about arrays Explore how to declare and manipulate data.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
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.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine.
An Introduction to Programming with C++ Sixth Edition
Computer Programming BCT 1113
Microsoft Visual Basic 2005: Reloaded Second Edition
JavaScript: Functions.
CIS16 Application Development and Programming using Visual Basic.net
Arrays Part 2.
Presentation transcript:

Introduction to Programming with C++ Fourth Edition Chapter 11: Arrays Introduction to Programming with C++ Fourth Edition

Objectives Declare and initialize a one-dimensional array Manipulate a one-dimensional array Pass a one-dimensional array to a function Use parallel one-dimensional arrays Declare and initialize a two-dimensional array Enter data into a two-dimensional array Introduction to Programming with C++, Fourth Edition

Using Arrays Simple or scalar variable - one that is unrelated to any other variable in memory Array - a group of variables that have the same name and data type and are related in some way Introduction to Programming with C++, Fourth Edition

One-Dimensional Arrays Each variable in a one-dimensional array is identified by a unique number called a subscript The subscript indicates the variable’s position in the array First variable in a one-dimensional array is assigned a subscript of 0 (zero), the second a subscript of 1 (one), and so on Elements – array variables Introduction to Programming with C++, Fourth Edition

Names of the Variables in a One-Dimensional Array Named prices Introduction to Programming with C++, Fourth Edition

Declaring and Initializing One-Dimensional Arrays Introduction to Programming with C++, Fourth Edition

The letters Array in Memory Introduction to Programming with C++, Fourth Edition

Storing Data in a One-Dimensional Array Introduction to Programming with C++, Fourth Edition

Manipulating One-Dimensional Arrays Display the contents of an array Access an array element using its subscript Search the array Calculate the average of the data stored in a numeric array Introduction to Programming with C++, Fourth Edition

Manipulating One-Dimensional Arrays (continued) Find the highest value stored in an array Update the array elements Sort the array elements Introduction to Programming with C++, Fourth Edition

Displaying the Contents of a One-Dimensional Array displayMonths() function – demonstrates how you can display the contents of the prices array Introduction to Programming with C++, Fourth Edition

displayMonths() Function Introduction to Programming with C++, Fourth Edition

Using the Subscript to Access an Element in a One-Dimensional Array Introduction to Programming with C++, Fourth Edition

Searching a One-Dimensional Array Search through an array looking for elements that are greater than a particular value Introduction to Programming with C++, Fourth Edition

Searching a One-Dimensional Array (continued) Introduction to Programming with C++, Fourth Edition

Calculating the Average Amount Stored in a One-Dimensional Numeric Array Introduction to Programming with C++, Fourth Edition

Determining the Highest Value Stored in a One-Dimensional Array Search through an array looking for an element whose value is larger than the largest value in the array so far (high) When the loop is finished, high will be the largest element in the array Introduction to Programming with C++, Fourth Edition

Determining the Highest Value Stored in a One-Dimensional Array (continued) Introduction to Programming with C++, Fourth Edition

Updating the Values Stored in a One-Dimensional Array Introduction to Programming with C++, Fourth Edition

Sorting the Data Stored in a One-Dimensional Array Arranging data in a specific order is called sorting Bubble sort algorithm: compare adjacent array elements and interchange (swap) the ones that are out of order Introduction to Programming with C++, Fourth Edition

Bubble Sort Introduction to Programming with C++, Fourth Edition

Passing a One-Dimensional Array to a Function Arrays are passed by reference Address of the first element is passed Include the name of the array in the function call Do not include the address-of (&) operator before the formal parameter’s name in the function header or prototype Formal parameter in the header/prototype should list data type, name, and empty square brackets Introduction to Programming with C++, Fourth Edition

Passing a One-Dimensional Array to a Function (continued) Introduction to Programming with C++, Fourth Edition

Using Parallel One-Dimensional Arrays Parallel arrays – two or more arrays whose elements are related by their position (subscript) in the arrays Introduction to Programming with C++, Fourth Edition

Using Parallel One-Dimensional Arrays (continued) Introduction to Programming with C++, Fourth Edition

Using Parallel One-Dimensional Arrays (continued) Introduction to Programming with C++, Fourth Edition

Two-Dimensional Arrays Two-dimensional array resembles a table Variables or elements are identified by a unique combination of two subscripts Subscripts specify the variable’s row and column position in the array Initialize elements by entering a separate initialValues section, enclosed in braces, for each row in the array Introduction to Programming with C++, Fourth Edition

Two-Dimensional Arrays (continued) Introduction to Programming with C++, Fourth Edition

Two-Dimensional Arrays (continued) Introduction to Programming with C++, Fourth Edition

Two-Dimensional Array in Memory Introduction to Programming with C++, Fourth Edition

Storing Data in a Two-Dimensional Array Introduction to Programming with C++, Fourth Edition

Storing Data in a Two-Dimensional Array (continued) Introduction to Programming with C++, Fourth Edition

Summary Array - a group of variables that have the same name and data type Subscript – a unique number assigned to each array element in memory One-dimensional array - a column of variables Two-dimensional array - resembles a table in that it has rows and columns You must declare all arrays and you should initialize them Introduction to Programming with C++, Fourth Edition

Summary (continued) Various array manipulations: Displaying the contents of an array Accessing an array element using its subscript Searching an array (“linear search”) Calculating the average of the data Finding the highest value stored in an array Updating the array elements Sorting the array elements Introduction to Programming with C++, Fourth Edition

Summary (continued) Arrays are passed to functions by reference Parallel arrays are two or more arrays whose elements are related by their subscript (or position) in the arrays Introduction to Programming with C++, Fourth Edition