Vectors.

Slides:



Advertisements
Similar presentations
Week 8 Arrays Part 2 String & Pointer
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.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Arrays, Vectors, and Strings Allocation and referencing.
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.
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.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
 2006 Pearson Education, Inc. All rights reserved Templates.
 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.
CMSC202 Computer Science II for Majors Lecture 09 – Overloaded Operators and More Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
ECE Application Programming
Operator Overloading; String and Array Objects
7 Arrays and Vectors.
Arrays Outline 1 Introduction 2 Arrays 3 Declaring Arrays
Standard Template Library (STL)
8 Pointers.
7 Arrays.
Introduction to Programming
7 Arrays.
Operator Overloading; String and Array Objects
Pointers and Pointer-Based Strings
Operator Overloading; String and Array Objects
C++ Programming Lecture 16 Arrays – Part III
4.9 Multiple-Subscripted Arrays
Introduction to Classes and Objects
Lecture 12 Oct 16, 02.
7. 11 Introduction to C++ Standard Library Class Template vector (Cont
Object Oriented Programming in java
Objects with Functions and Arrays
Class string and String Stream Processing
Topics discussed in this section:
Arrays ICS2O.
CISC181 Introduction to Computer Science Dr
Arrays ICS2O.
7 Arrays.
JavaScript: Arrays.
COP 3330 Object-oriented Programming in C++
7 Arrays and Vectors.
Arrays Arrays A few types Structures of related data items
C++ Programming Lecture 18 Pointers – Part II
C++ Programming Lecture 20 Strings
7 Arrays and Vectors.
Vectors.
4.1 Introduction Arrays A few types Structures of related data items
Presentation transcript:

vectors

Introduction to C++ Standard Library Class Template vector 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

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