7. 11 Introduction to C++ Standard Library Class Template vector (Cont

Slides:



Advertisements
Similar presentations
1 Pointers Lecture Introduction Pointers  Powerful, but difficult to master  Simulate pass-by-reference  Close relationship with arrays and.
Advertisements

4.1Introduction Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based arrays (C-like) –Arrays.
5 5 Arrays. OBJECTIVES In this lecture we will learn:  Case switch  To use the array data structure to represent a set of related data items.  To declare.
 2006 Pearson Education, Inc. All rights reserved Class string and String Stream Processing.
 2006 Pearson Education, Inc. All rights reserved Arrays.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
C++ for Engineers and Scientists Third Edition
 2006 Pearson Education, Inc. All rights reserved Arrays and Vectors.
 Pearson Education, Inc. All rights reserved Arrays.
 2006 Pearson Education, Inc. All rights reserved Arrays and Vectors.
CS0007: Introduction to Computer Programming Introduction to Arrays.
 2006 Pearson Education, Inc. All rights reserved Arrays.
CHAPTER 07 Arrays and Vectors (part I). OBJECTIVES 2 In this part you will learn:  To use the array data structure to represent a set of related data.
 2008 Pearson Education, Inc. All rights reserved Arrays and Vectors.
 C-style pointer-based arrays  Have great potential for errors and several shortcomings  C++ does not check whether subscripts fall outside the range.
 2008 Pearson Education, Inc. All rights reserved Pointers and Pointer-Based Strings.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
1 Arrays and Vectors Chapter 7 Arrays and Vectors Chapter 7.
Introduction to Programming Lecture 11. ARRAYS They are special kind of data type They are special kind of data type They are like data structures in.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
 2003 Prentice Hall, Inc. All rights reserved. 1 Vectors.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter Array Basics.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Arrays An array is an indexed data structure which is used to store data elements of the same data type. An array is an indexed data structure which is.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 20: Container classes; strings.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT:10 Advance Pointer Array, String and Dynamic Memory Allocation CS2311 Computer Programming.
CHAPTER 07 Arrays and Vectors (part II). OBJECTIVES In this part you will learn:  To pass arrays to functions.  Basic searching techniques.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
 2005 Pearson Education, Inc. All rights reserved Arrays.
 2008 Pearson Education, Inc. All rights reserved Arrays and Vectors.
 2006 Pearson Education, Inc. All rights reserved Arrays and Vectors.
4.1Introduction Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based arrays (C-like) –Arrays.
Arrays Chapter 7.
CMSC202 Computer Science II for Majors Lecture 09 – Overloaded Operators and More Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
Chapter 10 Operator Overloading; Class string
Array in C# Array in C# RIHS Arshad Khan
Operator Overloading; String and Array Objects
7 Arrays and Vectors.
Operator Overloading; Class string
Arrays Outline 1 Introduction 2 Arrays 3 Declaring Arrays
Standard Template Library (STL)
8 Pointers.
Vectors.
7 Arrays.
Introduction to Programming
7 Arrays.
Operator Overloading; String and Array Objects
Pointers and Pointer-Based Strings
Operator Overloading; String and Array Objects
4.9 Multiple-Subscripted Arrays
Introduction to Classes and Objects
Lecture 12 Oct 16, 02.
Object Oriented Programming in java
Class string and String Stream Processing
7 Arrays.
COP 3330 Object-oriented Programming in C++
7 Arrays and Vectors.
Arrays Arrays A few types Structures of related data items
Operator Overloading; String and Array Objects
C++ Programming Lecture 18 Pointers – Part II
C++ Programming Lecture 20 Strings
Lecture 14: Problems with Lots of Similar Data
Standard Version of Starting Out with C++, 4th Edition
Lecture 2 Arrays & Pointers September 7, 2004
7 Arrays and Vectors.
Vectors.
4.1 Introduction Arrays A few types Structures of related data items
Presentation transcript:

7. 11 Introduction to C++ Standard Library Class Template vector (Cont Available to anyone building applications with C++ Can be defined to store any data type Specified between angle brackets in vector< type > All elements in a vector are set to 0 by default Member function size obtains size of array Number of elements as a value of type size_t vector objects can be compared using equality and relational operators Assignment operator can be used for assigning vectors

7. 11 Introduction to C++ Standard Library Class Template vector (Cont vector elements can be obtained as an unmodifiable lvalue or as a modifiable lvalue Unmodifiable lvalue Expression that identifies an object in memory, but cannot be used to modify that object Modifiable lvalue Expression that identifies an object in memory, can be used to modify the object

7. 11 Introduction to C++ Standard Library Class Template vector (Cont vector member function at Provides access to individual elements Performs bounds checking Throws an exception when specified index is invalid Accessing with square brackets does not perform bounds checking

Outline fig07_26.cpp (1 of 6) Using const prevents outputVector from modifying the vector passed to it These vectors will store ints Function size returns number of elements in the vector

Outline (2 of 6) Comparing vectors using != fig07_26.cpp (2 of 6) Comparing vectors using != Copying data from one vector to another Assigning data from one vector to another

Outline (3 of 6) Comparing vectors using == fig07_26.cpp (3 of 6) Comparing vectors using == Displaying a value in the vector Updating a value in the vector Function at provides bounds checking

Outline (4 of 6) Display each vector element fig07_26.cpp (4 of 6) Display each vector element Input vector values using cin

Outline fig07_26.cpp (5 of 6)

Outline fig07_26.cpp (6 of 6) Call to function at with an invalid subscript terminates the program