An Introduction to Programming with C++ Fifth Edition

Slides:



Advertisements
Similar presentations
1.
Advertisements

Chapter 9: Advanced Array Manipulation
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Programming with Microsoft Visual Basic 2005, Third Edition
An Introduction to Programming with C++ Fifth Edition Chapter 5 The Selection Structure.
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation.
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
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.
An Introduction to Programming with C++ Fifth Edition Chapter 13 Sequential Access Files.
Arrays.
An Introduction to Programming with C++ Fifth Edition Chapter 6 More on the Selection Structure.
An Introduction to Programming with C++ Fifth Edition Chapter 8 More on the Repetition Structure.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
An Object-Oriented Approach to Programming Logic and Design Chapter 7 Arrays.
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
Searching and Sorting Arrays
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
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.
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.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Chapter 9: Advanced Array Concepts
Using Arrays and File Handling
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
A First Book of ANSI C Fourth Edition
Chapter 8 Arrays and Strings
Array Processing.
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.
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++ 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.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
 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 13 Strings.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
IT259 Foundation of Programming Using Java Unit 9 Seminar : (Chapter 8 ) Instructor : Vladimir Gubanov, PhD
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
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.
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.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
An Introduction to Programming with C++ Sixth Edition
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 7 Arrays.
Tutorial 11 Arrays Tutorial 11: Arrays.
CIS16 Application Development and Programming using Visual Basic.net
Arrays Part 2.
Presentation transcript:

An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays

Objectives Declare and initialize a one-dimensional array Manipulate a one-dimensional array Explain the bubble sort algorithm Pass a one-dimensional array to a function Use parallel one-dimensional arrays An Introduction to Programming with C++, Fifth Edition

Objectives (continued) Declare and initialize a two-dimensional array Enter data into a two-dimensional array Search a two-dimensional array Utilize a one-dimensional array in a .NET C++ program An Introduction to Programming with C++, Fifth Edition

Concept Lesson Using Arrays One-Dimensional Arrays Storing Data in a One-Dimensional Array Manipulating One-Dimensional Arrays Passing a One-Dimensional Array to a Function An Introduction to Programming with C++, Fifth Edition

Concept Lesson (continued) Using Parallel One-Dimensional Arrays Two-Dimensional Arrays Storing Data in a Two-Dimensional Array Searching a Two-Dimensional Array An Introduction to Programming with C++, Fifth Edition

Using Arrays Simple variable is unrelated to other variables in computer’s internal memory Also called a scalar variable Array is a group of variables Same name and data type Variables are related in some way Most commonly used One-dimensional Three-dimensional An Introduction to Programming with C++, Fifth Edition

One-Dimensional Arrays Visualize a one-dimensional array as a column of variables Subscript (or index) identifies each variable Indicates the variable’s position in the array Subscript of first variable is 0 Begin by populating the array so it does not contain garbage Element An Introduction to Programming with C++, Fifth Edition

One-Dimensional Arrays (continued) An Introduction to Programming with C++, Fifth Edition

Storing Data in a One-Dimensional Array Can use an assignment statement to enter data into an array See Figure 11-3 Can use >> and getline() See Figure 11-4 An Introduction to Programming with C++, Fifth Edition

Storing Data in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Storing Data in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Storing Data in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Manipulating One-Dimensional Arrays Common array manipulation functions Display the contents of an array Access an array element using its subscript Search an array Calculate the average of the data stored in an array Find the highest value stored in an array Update the array elements Sort the array elements using bubble sort An Introduction to Programming with C++, Fifth Edition

Displaying the Contents of a One-Dimensional Array Function may need simply to display the contents of an array An Introduction to Programming with C++, Fifth Edition

Displaying the Contents of a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Using the Subscript to Access an Element in a One-Dimensional Array Before accessing element, verify if subscript is valid An Introduction to Programming with C++, Fifth Edition

Searching a One-Dimensional Array Sales manager wants to determine the number of salespeople selling above a specific amount Function searches the sales array Array contains amount sold by each salesperson Look for values greater than the amount provided by sales manager An Introduction to Programming with C++, Fifth Edition

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

Calculating the Average Amount Stored in a One-Dimensional Numeric Array Prof. Jeremiah wants to calculate and display average test score earned by students on final Function adds test scores that are stored in array Then, divide sum by number of elements An Introduction to Programming with C++, Fifth Edition

Calculating the Average Amount Stored in a One-Dimensional Numeric Array (continued) An Introduction to Programming with C++, Fifth Edition

Determining the Highest Value Stored in a One-Dimensional Array Sharon Johnson keeps track of the amount of money she earns each week Function displays highest amount earned in a week Stores pay amounts in a one-dimensional array An Introduction to Programming with C++, Fifth Edition

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

Updating the Values Stored in a One-Dimensional Array Sales manager at Jillian Company wants a function that increases the price of each item company sells Function stores prices in a one-dimensional array Then, increase value stored in each element Also, display each item’s new price on screen An Introduction to Programming with C++, Fifth Edition

Updating the Values Stored in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Sorting the Values Stored in a One-Dimensional Array Arranging data in a specific order is called sorting Ascending or descending order Bubble sort is quick and easy (for small arrays) Adjacent elements that are out of order are swapped An Introduction to Programming with C++, Fifth Edition

Sorting the Values Stored in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Sorting the Values Stored in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Sorting the Values Stored in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Sorting the Values Stored in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Sorting the Values Stored in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Sorting the Values Stored in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Sorting the Values Stored in a One-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Passing a One-Dimensional Array to a Function By default, scalar variables are passed by value To pass by reference, use address-of (&) operator Arrays in C++ are passed by reference More efficient Address of first element is passed to function Address-of operator is not used An Introduction to Programming with C++, Fifth Edition

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

Using Parallel One-Dimensional Arrays Takoda Tapahe wants a program that displays the price of the item whose product ID she enters An Introduction to Programming with C++, Fifth Edition

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

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

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

Two-Dimensional Arrays Two-dimensional array resembles a table Elements are in rows and columns Each element is identified by two subscripts Subscripts specify the variable’s row and column position in the array An Introduction to Programming with C++, Fifth Edition

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

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

Storing Data in a Two-Dimensional Array You can use an assignment statement to enter data into a two-dimensional array Or use >> and getline() Use two loops to access every element in a two-dimensional array One loop tracks row subscript Other loop tracks column subscript An Introduction to Programming with C++, Fifth Edition

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

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

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

Searching a Two-Dimensional Array Two one-dimensional (parallel) arrays can be replaced with one two-dimensional array An Introduction to Programming with C++, Fifth Edition

Searching a Two-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Searching a Two-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Searching a Two-Dimensional Array (continued) An Introduction to Programming with C++, Fifth Edition

Summary An array is a group of variables that have the same name and data type and are related in some way One-dimensional Visualize as a column of variables Two-dimensional Visualize as a table You must declare an array before you can use it Each elements in a one-dimensional array is assigned a subscript First element has subscript 0 An Introduction to Programming with C++, Fifth Edition

Summary (continued) Parallel arrays are two or more arrays whose elements are related by their subscript in the arrays To create a two-dimensional array specify the number of rows and columns Each element is identified by two subscripts First subscript represents the element’s row location Second subscript represents its column location Use two loops to access every element in a two-dimensional array An Introduction to Programming with C++, Fifth Edition

Application Lesson: Using Arrays in a C++ Program Lab 11.1: Stop and Analyze Lab 11.2 Program should either display the monthly rainfall amounts on the screen or calculate and display the total rainfall amount Lab 11.3 Modified program will use a value-returning function, calcTotal(), to calculate the total rainfall amount Lab 11.4: Desk-Check Lab Lab 11.5: Debugging Lab An Introduction to Programming with C++, Fifth Edition