Hello,
Can someone help me with the answer for this question. This is an exam I did a couple of week back and I don't understand why I got it wrong. AND I don't understand the answer the instructor gave me either.
QUESTION
Suppose the following partial definition for a vector class. Fill the method indicated below so that it functions as described in the comments. You should write your answer in C++ or as close to C++ as you can (minor syntactic errors will be ignored!).
Can someone help me with the answer for this question. This is an exam I did a couple of week back and I don't understand why I got it wrong. AND I don't understand the answer the instructor gave me either.
QUESTION
Suppose the following partial definition for a vector class. Fill the method indicated below so that it functions as described in the comments. You should write your answer in C++ or as close to C++ as you can (minor syntactic errors will be ignored!).
Code:
#ifndef VECTOR_H_ #define VECTOR_H_ #include <cstring> namespace somenamespace{ template <typename ELEMENT_TYPE> class vector { private: ELEMENT_TYPE* data; size_t num_items; size_t current_capacity; const static size_t INITIAL_CAPACITY = 10; public: vector<ELEMENT_TYPE>(): current_capacity(INITIAL_CAPACITY), num_items(0), data(new ELEMENT_TYPE[INITIAL_CAPACITY]){} //************************************************************************* // Fill this function so that it returns the element // currently stored at index passed in as parameter. //************************************************************************* ELEMENT_TYPE& get(size_t index) { } }; }; endif /*VECTOR_H_*/
Comment