13. Vectors - ENGR 101, Section 100 Vectors ENGR 101,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ENGR 101, Section 100 M. Wellman 1 Vectors ENGR 101, Lecture 13: 27 Oct 10 Announcements Project 5 due tonight (9pm) Exam 2 on Wed 3 Nov (6pm) contact Nader Jawad (njawad@umich.edu) about conflicts Gateway exam coming (probably in lab)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENGR 101, Section 100 M. Wellman 2 Generalizing from Strings string : compound data object represents sequence of char s supports array semantics (index access to elements) How can we construct a compound data object to represent sequences of some other type? C++ native arrays vector class Vector Class Vectors can be used to make sequences of anything : int, double, char, string, … vector is a generic type Include library header files: #include <vector> Declare a vector (basic form): vector < T > identifier ; For example: vector <int> intlist; vector <double> doublelist; vector <string> stringlist;
Background image of page 2
ENGR 101, Section 100 M. Wellman 3 Vector Definition To declare and define a vector of specified length: vector < T > identifier ( len ); where len evaluates to a positive integer For example: vector <int> intlist(5); vector <double> doublelist(10); vector <string> stringlist(25); defines initial vector length (can be changed subsequently) Vector Definition with Initialization To declare and define with initial value for elts: vector < T > identifier ( len , exp ); where exp evaluates to something of type T For example: vector <int> intlist(5,-1);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/25/2011 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

Page1 / 11

13. Vectors - ENGR 101, Section 100 Vectors ENGR 101,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online