{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

13. Vectors

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

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

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 ([email protected]) about conflicts Gateway exam coming (probably in lab)

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

View Full Document
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;
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);

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern