{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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 ([email protected]) about conflicts Gateway exam coming (probably in lab)
Image of page 1

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

View Full Document Right 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;
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);
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern