Lecture+17 - Engineering 101 Engineering 101 Lecture 17...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Engineering 101 Engineering 101 Lecture 17 11/1/07 Vectors and Vectors of Vectors Quote of the Day Quote of the Day Whatever you do will be insignificant, but it is very important that you do it. ­ Mahatma Gandhi Converting a character to uppercase Converting a character to uppercase int toupper ( int c ) Converts parameter c to its uppercase equivalent if c is a lowercase letter and has an uppercase equivalent. If no such conversion is possible, the value returned is c unchanged. A lowercase letter is any of: a b c d e f g h i j k l m n o p q r s t u v w x y z This translates respectively to: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z The return and input values can also be chars (they are special 8­bit ints) “cin >> str;” versus getline(cin, str) cin ignores whitespace and uses it to “separate” input getline() reads in an entire line of text, including spaces A newline is left in the iostream If you use getline() after a “cin >>”, then the newline will be read and getline() will stop A newline is removed from the iostream and discarded Use “cin >> str” to get strings from the user instead How to address this: int x; string dummy; cin >> x; getline(cin, dummy); However, this will not allow spaces as part of the string Generic Types Generic Types Sometimes we may want to write a function but make it useful for multiple data types. Example: What if we want to swap two numbers? We can’t just type: a=b; b=a; (Why?) Generic Types Generic Types Consider the function: void swap (int & a, int & b) { int c=a; a=b; b=c; return; } Generic Types Generic Types This definition is only valid for integers although the procedure could work for most anything void swap (int & a, int & b) { int c=a; a=b; b=c; return; } Generic Types Generic Types This definition is only valid for integers although the procedure could work for most anything template <class T> void swap (T & a, T & b) { T c=a; a=b; b=c; return; } Generic Types Generic Types Using the Generic swap procedure: main ( ) { int a=5, b=4; string s(“hello”), t(“world); swap(a, b); swap(s, t); } The pair type #include <utility> Represents a generic pair of two numbers. For example if you want to make a string associated with a number: pair<int, string> a; a.first = 1; a.second= “The first string.”; Classes that Use Classes that Use Generic Typing Making Lists of Things Making Lists of Things Often times we want to make lists of things that are not characters For these we can use another class called the vector class #include <vector> Vectors Vectors Vectors can be used to make lists of anything: int, double, char, string, …. To declare a vector you have to specify the type you are making a list of. vector <type> identifier; Vectors Vectors For example: vector <int> intlist; vector <double> doublelist; vector <string> stringlist; Vectors Vectors Typically we also want to tell how long this list will be: vector <int> intlist(5); vector <double> doublelist(10); vector <string> stringlist(25); Vectors Vectors We can also specify what to initialize the values in the list to: vector <int> intlist(5, ­1); vector <double> doublelist(10, 0.0); vector <string> stringlist(25, “none”); Vectors Vectors Individual parts of the list can be accessed using array semantics vector <int> intlist(5, ­1); intlist[ 1 ] = 10; Vectors Vectors Individual parts of the list can be accessed using array semantics vector <int> intlist(5, ­1); intlist[ 1 ] = 10; for(i=2; i < 5; i = i + 1) intlist[ i ] = intlist[ i­1 ] + 1; Vectors Vectors Alternately we can use the safer at( ) method to index the list vector <int> intlist(5, ­1); intlist.at(1) = 10; for(i=2; i < 5; i = i + 1) intlist.at( i ) = intlist. at( i­1 ) + 1; Exercise Exercise What will be output? 1­ 2 4 8 16 32 2­ 32 16 8 4 2 3­ 2 2 2 2 2 4­ 2 2 2 4 2 ; Exercise Exercise What will be output? 1­ 2 4 8 16 32 2­ 32 16 8 4 2 3­ 2 2 2 2 2 4­ 2 2 2 4 2 ; Exercise Exercise vector <int> list(5,1); int a; list[4]=2; for(a=3; a>=0; a­­) list[a]= 2*list[a+1]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 1 1 1 1 Exercise Exercise vector <int> list(5,1); int a; list[4]=2; for(a=3; a>=0; a­­) list[a]= 2*list[a+1]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 1 1 1 2 Exercise Exercise vector <int> list(5,1); int a; list[4]=2; for(a=3; a>=0; a­­) list[a]= 2*list[a+1]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 1 1 4 2 Exercise Exercise vector <int> list(5,1); int a; list[4]=2; for(a=3; a>=0; a­­) list[a]= 2*list[a+1]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 1 8 4 2 Exercise Exercise vector <int> list(5,1); int a; list[4]=2; for(a=3; a>=0; a­­) list[a]= 2*list[a+1]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 16 8 4 2 Exercise Exercise vector <int> list(5,1); int a; list[4]=2; for(a=3; a>=0; a­­) list[a]= 2*list[a+1]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 32 16 8 4 2 Exercise Exercise What will be output? 1­ 1 2 4 8 16 2­ 16 8 4 2 1 3­ 2 4 8 16 32 4­ 32 16 8 4 2 ; Exercise Exercise What will be output? 1­ 1 2 4 8 16 2­ 16 8 4 2 1 3­ 2 4 8 16 32 4­ 32 16 8 4 2 ; Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 1 1 1 1 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 1 0 1 1 b 1 0 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 2 1 1 1 b 1 0 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 2 2 2 1 b 1 0 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 2 2 4 1 b 1 1 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 2 3 4 2 b 1 0 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 2 3 4 4 b 1 1 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 2 3 4 8 b 1 2 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 2 4 4 8 b 2 0 Exercise Exercise vector <int> list(5,1); int a, b; for(a=0; a<5; a++) for(b=0; b<a; b++) list[a]= list[a]+list[b]; for(a=0; a<5; a++) cout << list[a] << “ “; cout << endl; 1 a 2 4 4 8 16 b 3 Vectors Vectors Other methods also exist to manipulate vectors: v.back( ) refers to the last element v.front( ) refers to the first element v.empty( ) true if the vector is empty v.clear( ) empties the vector Vectors Vectors Other methods also exist to manipulate vectors: v.pop_back( ) v.push_back(e) v.resize(newsize) v.resize(newsize,e) removes the last element appends another element changes size of the vector and puts e into any new elements What is the purpose of this code? What is the purpose of this code? 1­ Print out each word in a line separately 2­ Read successive lines into a vector of strings 3­ Remove all the spaces in a line 4­ Read each word in a line into a vector of strings What is the purpose of this code? What is the purpose of this code? 1­ Print out each word in a line separately 2­ Read successive lines into a vector of strings 3­ Remove all the spaces in a line 4­ Read each word in a line into a vector of strings int n; vector <string> list; string line; getline(cin, line); n = line.find(“ “); while(n != line.npos){ while(n==0){ line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text int n; vector <string> list; string line; getline(cin, line); line A n = line.find(“ “); while(n != line.npos){ while(n==0){ n? line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text line of list text empty int n; vector <string> list; string line; getline(cin, line); line A n = line.find(“ “); while(n != line.npos){ while(n==0){ 1 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text line of list text empty int n; vector <string> list; string line; getline(cin, line); line A n = line.find(“ “); while(n != line.npos){ while(n==0){ 1 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text line of list text empty int n; vector <string> list; string line; getline(cin, line); line A n = line.find(“ “); while(n != line.npos){ while(n==0){ 1 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text line of list text empty int n; vector <string> list; string line; getline(cin, line); line A n = line.find(“ “); while(n != line.npos){ while(n==0){ 1 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text line of list text empty int n; vector <string> list; string line; getline(cin, line); line A n = line.find(“ “); while(n != line.npos){ while(n==0){ 1 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text line of list text empty int n; vector <string> list; string line; getline(cin, line); line A n = line.find(“ “); while(n != line.npos){ while(n==0){ 1 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text line of list [0] text A int n; vector <string> list; string line; getline(cin, line); line line of n = line.find(“ “); while(n != line.npos){ while(n==0){ 1 n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text A int n; vector <string> list; string line; getline(cin, line); line line of n = line.find(“ “); while(n != line.npos){ while(n==0){ 0 n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text A int n; vector <string> list; string line; getline(cin, line); line line of n = line.find(“ “); while(n != line.npos){ while(n==0){ 0 n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text A int n; vector <string> list; string line; getline(cin, line); line line of n = line.find(“ “); while(n != line.npos){ while(n==0){ 0 n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text A int n; vector <string> list; string line; getline(cin, line); line line of n = line.find(“ “); while(n != line.npos){ while(n==0){ 0 n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text A int n; vector <string> list; string line; getline(cin, line); line line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 0 A n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text int n; vector <string> list; string line; getline(cin, line); line line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 4 A n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text int n; vector <string> list; string line; getline(cin, line); line line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 4 A n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text int n; vector <string> list; string line; getline(cin, line); line line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 4 A n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text int n; vector <string> list; string line; getline(cin, line); line line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 4 A n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text int n; vector <string> list; string line; getline(cin, line); line line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 4 A n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text int n; vector <string> list; string line; getline(cin, line); line line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 4 A n list [0] line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text int n; vector <string> list; string line; getline(cin, line); line of line n = line.find(“ “); while(n != line.npos){ while(n==0){ 4 n list [0] line.erase(0,1); n = line.find(“ “); list [1] } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text A line int n; vector <string> list; string line; getline(cin, line); line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 4 n list [0] line.erase(0,1); n = line.find(“ “); list [1] } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text A line int n; vector <string> list; string line; getline(cin, line); line of text n = line.find(“ “); while(n != line.npos){ while(n==0){ 0 n list [0] line.erase(0,1); n = line.find(“ “); list [1] } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text A line int n; vector <string> list; string line; getline(cin, line); line of n = line.find(“ “); while(n != line.npos){ while(n==0){ 2 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text list [0] list [1] A line int n; vector <string> list; string line; getline(cin, line); line n = line.find(“ “); while(n != line.npos){ while(n==0){ 2 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text list [0] list [1] list [2] A line of int n; vector <string> list; string line; getline(cin, line); line n = line.find(“ “); while(n != line.npos){ while(n==0){ 2 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text list [0] list [1] list [2] A line of int n; vector <string> list; string line; getline(cin, line); line n = line.find(“ “); while(n != line.npos){ while(n==0){ 0 n line.erase(0,1); n = line.find(“ “); } if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text text list [0] list [1] list [2] A line of int n; vector <string> list; string line; getline(cin, line); line text n = line.find(“ “); while(n != line.npos){ while(n==0){ 0 n list line.erase(0,1); n = line.find(“ “); list } list if(line.size()!=0){ if(n == line.npos) list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text [0] [1] [2] A line of int n; vector <string> list; string line; getline(cin, line); line text n = line.find(“ “); while(n != line.npos){ while(n==0){ n npos list line.erase(0,1); n = line.find(“ “); list } list if(line.size()!=0){ if(n == line.npos) list list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text [0] [1] [2] [3] A line of text int n; vector <string> list; string line; getline(cin, line); line text n = line.find(“ “); while(n != line.npos){ while(n==0){ n npos list line.erase(0,1); n = line.find(“ “); list } list if(line.size()!=0){ if(n == line.npos) list list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text [0] [1] [2] [3] A line of text int n; vector <string> list; string line; getline(cin, line); line text n = line.find(“ “); while(n != line.npos){ while(n==0){ n npos list line.erase(0,1); n = line.find(“ “); list } list if(line.size()!=0){ if(n == line.npos) list list.push_back(line); else{ list.push_back(line.substr(0,n)); line.erase(0,n); } } n = line.find(“ “); } Using Vectors to Using Vectors to Handle Text [0] [1] [2] [3] A line of text Which of the functions will successfully return the string Which of the functions will successfully return the string containing the letters in the incoming string, but in reverse order? reverse(“hello”)==“olleh” 1. 2. 3. Which of the functions will successfully return the string Which of the functions will successfully return the string containing the letters in the incoming string, but in reverse order? reverse(“hello”)==“olleh” 1. 2. 3. Vectors Vectors Vectors can also be used to store lists of lists vector< vector <int> > table; Vectors of Vectors Vectors of Vectors If you think of vector <int> as a row of integers then you can think of vector <vector <int> > as a series of rows vector <vector <int> > table; table[0] = 1 2 3 5 7 Note this is table[1] = 4 2 7 3 0 just a schematic table[2] = 5 5 ­1 2 6 you can’t actually assign arrays this way Vectors of Vectors Vectors of Vectors To access an individual number you need to designate which item in the row 2 2 3 7 5 3 7 0 vector <vector <int> > table; table[0] = 1 table[1] = 4 table[2] = 5 5 ­1 table[0][2] == 3 2 6 table[2][3] == 2 Vectors of Vectors Vectors of Vectors Uses of Vectors of Vectors: Tables of data double Ex, Ey, Ez; double Mx, My, Mz; double Cx, Cy, Cz; //earth data //moon data //comet data Vectors of Vectors Vectors of Vectors Using of Vectors of Vectors: Tables of data vector <double> Earth(3, 0.0); data vector <double> Moon(3, 0.0); data vector <double> Comet(3, 0.0); data //earth //moon //comet Vectors of Vectors Vectors of Vectors Using of Vectors of Vectors: Tables of data vector <vector <double> > PlanetData; Vectors of Vectors Vectors of Vectors Creating of Vectors of Vectors: Assigning data to the elements vector <vector <double> > PlanetData(3); vector <double> row(3, 0.0); for(int i=0; i < 3; i=i+1){ PlanetData[i] = row; } Vectors of Vectors Vectors of Vectors Creating of Vectors of Vectors: An easier way of assigning data to the elements vector <vector <double> > PlanetData(3); for(int i=0; i < 3; i=i+1){ PlanetData[i] .assign(3, 0.0); } Vectors of Vectors Vectors of Vectors Creating of Vectors of Vectors: The easiest way of assigning data to the elements vector <double> row(3, 0.0); vector <vector <double> > PlanetData(3, row); Vectors of Vectors Vectors of Vectors Accessing of Vectors of Vectors: Printing the data vector <double> row(3, 0.0); vector <vector <double> > PlanetData(3, row); int i, j; for(i=0; i < PlanetData.size(); i=i+1){ for(j=0; j < PlanetData[ i ].size(); j=j+1) cout << PlanetData[ i ][ j ] << “ “; cout << endl; } Vectors of Vectors Vectors of Vectors Accessing of Vectors of Vectors: Printing the data vector <double> row(3, 0.0); vector <vector <double> > PlanetData(3, row); int i, j; for(i=0; i < PlanetData.size(); i=i+1){ for(j=0; j < PlanetData.at( i ).size(); j=j+1) cout << PlanetData.at( i ).at( j ) << “ “; cout << endl; } What will the contents of table be after the for loops What will the contents of table be after the for loops 1 2 execute? 3 4 000 012 024 012 024 036 123 246 369 112 124 136 What will the contents of table be after the for loops What will the contents of table be after the for loops 1 2 execute? 3 4 000 012 024 012 024 036 123 246 369 112 124 136 Next Lecture Next Lecture Sorting and Recursion ...
View Full Document

This note was uploaded on 03/12/2010 for the course ENGIN 101 taught by Professor Jeffringenberg during the Fall '07 term at University of Michigan.

Ask a homework question - tutors are online