// Dave Goldsmith // Redwood High School // C++ Computer Programming // March 19, 2009 // Vector2.cpp #include #include #include using namespace std; void GetWords(vector & words) { // Get words from the user, one-at-a-time, and add them to the vector do { // Increase the vector size by 1 words.resize(words.size()+1); cout << "Enter a word (ENTER when done): "; getline(cin, words[words.size()-1]); } while (words[words.size()-1] != ""); // Decrease the vector size by 1 to account for the empty spot at the end words.resize(words.size()-1); } void ShowData(vector words) { cout << "\nSize of the vector: " << words.size() << endl; cout << "First word in the vector: " << words.front() << endl; cout << "Last word in the vector: " << words.back() << endl; } void ShowWords(vector words) { cout << "\nList of all words in the vector:\n"; for (int counter=0; counter words(0); GetWords(words); ShowData(words); ShowWords(words); }