exam3another - The Best Lecture You Have Ever Slept Through...

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

View Full Document Right Arrow Icon
The Best Lecture  You Have Ever Slept Through Samantha Loux Mark Sprague Sarah Squire Trust us, we tested it.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Intro: Vectors, Strings, and Chars  (OH MY!) Start at offset = 0 Offset is the position of the type Last element/position is located at x.size()-1 Warning: x.at()  vs.  x[] x.at() checks that you do not address beyond  the length of the string, but does not always  check for negative addresses. Check shows when trying to execute, code will  compile use x.at()
Background image of page 2
Strings and Chars Strings could be described as having type char String.at(i) refers to a char at position i Length is not set for strings String.size() returns number of chars Chars can be assigned to negative i  values But this is not recommended string = “s”  vs.  char = ‘c’
Background image of page 3

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

View Full DocumentRight Arrow Icon
Comparing: Strings and Chars Chars have associated number values used in  comparisons Whitespace < period(.) < uppercase <  lowercase Strings: for strings S and W compares S.at(0)  and W.at(0), if equal compares S.at(1) and  W.at(1), etc. If S.at(i)!=W.at(i), depending on comparison  (==, !=, <, >) return is based on comparison  of chars at i
Background image of page 4
getline() Reads in line as a string Ex: getline(cin,s), getline(infile,line) Warning: cin>>getline(cin,s); does not  compile
Background image of page 5

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

View Full DocumentRight Arrow Icon
Strings vs. C-strings C-strings are better understood by the  compiler Certain methods require use of C-strings Conversion: string = string.c_str(); Ex: Reading in a file name to open a file
Background image of page 6
Vectors: The Beginnings #include <vector> vector <type> identifier; vector <type> identifier(int); int = size of vector vector <type> identifier(int,e); e = element of <type> , initializes values to e Warning: printing “empty” vector location prints: 0 for ints and doubles (nothing) for strings and chars
Background image of page 7

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

View Full DocumentRight Arrow Icon
Vectors of Vectors vector < vector <int> > v; Must space like this or will not compile because  similar to << and >> for reading information This vector expects to be filled with another  vector
Background image of page 8
Visualizing Vectors of Vectors vector.at(rows).at(columns) columns is the inner vector Ex: Populating a vector with a vector vector< vector<int> > pos; vector<int> temp; int x=3,y=5; temp.push_back(x); temp.push_back(y); pos.push_back(temp) Now pos.at(0) has elements from temp 2 elements in inner vector = 2 columns        [0]     [1][0]    3       5
Background image of page 9

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

View Full DocumentRight Arrow Icon
Tidbits swap(a,b) – a and b must be same type #include <complex> type can be any numeric type, real or 
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/16/2010 for the course ENGR 101 Sectio taught by Professor Ringenberg during the Fall '08 term at University of Michigan.

Page1 / 40

exam3another - The Best Lecture You Have Ever Slept Through...

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

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