Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a class called VectorDouble that is like a class for a vector with base t

ID: 3539030 • Letter: D

Question

Define a class called VectorDouble that is like a class for a vector with base type double. Your class VectorDouble will have a private member variable for a dynamic array of doubles. It will also have two member variables of type int, one called max_count for the size of the dynamic array of doubles; and one called count for the number of array positions currently holding values. (max_count is the same as the capacity of a vector; count is the same as the size of a vector)

If you attempt to add an element (a value of type double) to the vector object of the class VectorDouble and there is no more room, then a new dynamic array with twice the capacity of the old dynamic array is created and the values of the old dynamic array are copied to the new dynamic array.

Your class should have all of the following:

Explanation / Answer

#include using namespace std; // VectorDouble class header file class VectorDouble { public: // constructor for an empty vector of type double VectorDouble(); // constructor that take an int argument for an integer size of and array VectorDouble(int initial_size); // copy constructor VectorDouble(VectorDouble &object); // destructor to return dynamic memory to the freestore ~VectorDouble(); // overloaded operator = for VectorDouble class VectorDouble& operator =(const VectorDouble &source); // overloaded operator == for VectorDouble class friend bool& operator ==(const VectorDouble &this_vector, VectorDouble &other_vector); // adds a new element at the end of the array void push_back(); // returns allocated size of VectorDouble dynamic array int capacity(); // returns used size of the VectorDouble object int size(); // allocates a specified block of memory for specified number of double // type values void reserve(int new_reserve); // changes the size of the dynamic array void resize(int new_size); // returns the value at the specified index double value_at(int index); // changes the value at the specified index to double value d void change_value_at(double d, int index); private: int count; int max_count; int index_pointer; *index_pointer = new double[100]; };
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote