#include #include using namespace std; class vectorofint { protected: int * data; int capacity; int numitems; public: vectorofint(); ~vectorofint(); void resize(int newsize); void push_back(int value); int back(); void pop_back(); int & at(int position); int size(); }; vectorofint::vectorofint() { capacity = 0; numitems = 0; data = nullptr; } vectorofint::~vectorofint() { delete [] data; } void vectorofint::resize(int newsize) { if (newsize < capacity) return; int * newdata = new int[newsize]; for (int i = 0; i < numitems; i += 1) newdata[i] = data[i]; delete [] data; data = newdata; capacity = newsize; } void vectorofint::push_back(int value) { if (numitems >= capacity) { int newsize = capacity * 2; if (newsize <= capacity) newsize = capacity + 1; resize(newsize); } data[numitems] = value; numitems += 1; } int vectorofint::back() { assert(numitems > 0); return data[numitems - 1]; } void vectorofint::pop_back() { assert(numitems > 0); numitems -= 1; } int & vectorofint::at(int position) { assert(position >= 0); assert(position < numitems); return data[position]; } int vectorofint::size() { return numitems; } int main() { vectorofint V; V.push_back(123); V.push_back(99); V.push_back(7); V.push_back(12'345'678); V.at(2) = 777777; for (int i = 0; i < V.size(); i += 1) cout << V.at(i) << "\n"; }