Problems
Arrays¶
- What are data structures?
- What are the limitations of arrays?
Vector Concepts¶
- What happens to a vector when it reaches capacitry, as opposed to an array?
- What fundamental attributes are required in order to create a vector class?
- What does the constructor of a vector class do? What about the destructor?
- What is the difference between a vector's capacity and a vector's size?
- What are the big O's of a vector's push back, insert, and erase functions?
Vectors - Standard Template Library¶
CPP Vector reference: http://www.cplusplus.com/reference/vector/vector/
- What is the standard template library?
- What header needs to be included to utilize vectors?
- What functions are utilized to add and remove items from the end of the vector?
- What functions are utilized to check the vectors size and capacity?
- Write a two vector declarations. One that stores integers and another that stores objects from a class named Students.
- What does the following program output?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream> #include <vector> using namespace std; int main() { vector<int> vect; for (int i = 0; i < 5; i++) vect.push_back(i); for (int i = 0; i < 5; i++) cout << vect[i] << " "; cout << endl; for (int i : vect) cout << i << " "; }
- What does the following program output?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream> #include <vector> using namespace std; int main() { vector<int> vect(5); for (int i : vect) cout << i << " "; vect.resize(3); vect[1] = 5; cout << endl; for (int i : vect) cout << i << " "; }
- What does the following program output?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <iostream> #include <vector> using namespace std; int main() { vector<int> vect(1); cout << "size: " << vect.size() << endl; cout << "capacity: " << vect.capacity() << endl << endl; vect.push_back(1); cout << "size: " << vect.size() << endl; cout << "capacity: " << vect.capacity() << endl << endl; vect.push_back(1); cout << "size: " << vect.size() << endl; cout << "capacity: " << vect.capacity() << endl << endl; vect.push_back(1); vect.push_back(1); cout << "size: " << vect.size() << endl; cout << "capacity: " << vect.capacity() << endl << endl; }