class vector {
    int sz;       // number of elements
    double* elem; // address of first element
    int space;    // number of elements plus "free space"/"slots"
public:
    vector();
    void reserve(int newalloc);
    int  capacity() const { return space; }
    int size() const { return sz; }
    void resize(int newsize);
};
vector::vector() :sz(0), elem(0), space(0) {}
void vector::reserve(int newalloc) {
    if (newalloc<=space) return;      // never decrease allocation
    double* p = new double[newalloc];        // allocate new space
    for (int i=0; i<sz; ++i) p[i] = elem[i]; // copy old elements
    delete[] elem;                          // deallocate old space
    elem = p;
    space = newalloc;        
}
void vector::resize(int newsize) {
// make the vector have newsize elements
// initialize each new elements with the default value 0.0
    reserve(newsize);
    for (int i=sz; i<newsize; ++i) elem[i] = 0;    // initialize new elements 
    sz = newsize;    
}
int main() {
    vector v;
    v.reserve(10);
    std::cout << "\nv.capacity() = " << v.capacity() << '\n';
    std::cout <<"v.size() = " << v.size() << '\n';
    v.resize(4);
    std::cout <<"v.size() = " << v.size() << '\n';
    return v.capacity();
}