Question:

Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill 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_countis 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 VectorDoubleand 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:

• Three constructors:
1. A default constructor that creates a dynamic array for 50 elements.
2. A constructor with one int argument for the number of elements in the initial dynamic array.
3. A copy constructor.
• A destructor.
• A suitable overloading of the equality operator ==. To be equal, the values of count and the count array elements must be equal, but the values of max_count need not be equal.
• Member functions push_back, capacity, size, reserve, and resizethat behave the same as the member functions of the same names for vectors.
• See documentation for the vector class here: http://www.cplusplus.com/reference/vector/vector/ (Links to an external site.)Links to an external site.
• For push_back(), you should increase the capacity of the vector by 2 if there is not room to push an additional element (i.e.  countequals max_count).
• For reserve()and resize(), make sure to copy the current contents of the VectorDoubleinto the new underlying array.
• Two member functions to give your class the same utility as the square brackets:
1. value_at(i), which returns the value of the i-th element in the dynamic array; and
2. change_value_at(d, i), which changes the double value at the i-th element of the dynamic array to d.
• Enforce suitable restrictions on the arguments to value_atand change_value_at.
• Make sure indices are in bounds of the array. If they are out of bounds, throw a std::logic_error
• (Your class will not work with the square brackets. It can be made to work with square brackets, but we have not covered the material which tells you how to do that.)
• You may not use the Standard’s

Some other useful notes:

• A skeleton of the class has been provided to help you get started. Do not change the return types, argument types, or number of arguments to each function.
• Do not change what is already in VectorDouble.h. You may add functions, but do not change anything that is already there.
• I have provided a working <<operator for the VectorDoubleclass. The testing framework uses this operator extensively - do not change its behavior in any way.
• Get basic working versions of the constructors, copy constructor, and assignment operator working first.
• If you don’t, the testing code will crash when it hits points that expect these to be implemented. If these functions don’t succeed in some basic manner, it’s highly likely your program will crash. This is true for any class, not just VectorDouble.
• You’ll notice a friend int reserved_driver_main()is in the VectorDouble header. This is how the testing framework accesses the private members of the VectorDouble(since the function is a friend!). This was done so that the tests don’t rely on functions like capacity(), size(), value_at(), and change_value_at(). If the framework did rely on these, and you hadn’t implemented them correctly, you would be guaranteed to fail everytest case. This allows more partial credit. However, if you copy and paste the testing code into your user_main(), your program won’t compile (the intention of the providing the testing code was not to copy and paste it, but to show you what cases you need to handle).
• Two ways around this:
1. Make the private members public ( arr, max_count, count). Then there’s no need for the friend function, and the you can copy the testing code into your IDE/ user_main().
2. After you’ve implemented capacity(), size(), value_at(), and change_value_at(), replace the uses of private members with these functions appropriately in the testing code.
• Here is the Header file
• ifndef DYNAMICARRAY_H
define DYNAMICARRAY_H

include <iostream>

using namespace std;

class VectorDouble {
private:
int max_count;
int count;
double* arr;
public:
//default constructor
VectorDouble();
//parameterized constructor takes an int argument for an integer size of the array
VectorDouble(int max_count);
//copy constructor
VectorDouble(const VectorDouble& copy);

//Destructor
~VectorDouble();
//operations of vector class
//overloaded operator = for VectorDouble class
VectorDouble operator =(VectorDouble& copy);
// overloaded operator == for VectorDouble class
bool operator ==(VectorDouble b) const;
//to insert an element into a double vector
void push_back(double num);
int capacity();
int size();
void reserve(unsigned int size);
void resize(unsigned size, double defaultVal = 0.0);
double value_at(unsigned int i);
void change_value_at(double newValue, unsigned int i);
friend ostream& operator<<(ostream& os, const VectorDouble &vd);
// DO NOT CHANGE THE FOLLOWING LINE OF CODE. It is for the testing framework
// DO NOT IMPLEMENT THE FOLLOWING FUNCTION. It is implemented by the testing framework
friend int reserved_driver_main();
};

endif

Similar Solved Questions

2-2 Chemoautotrophic bacteria are responsible for the oxidation of NH:-N to NO -N in many biologi...
please help 2-2 Chemoautotrophic bacteria are responsible for the oxidation of NH:-N to NO -N in many biological wastewater treatment processes. These bacteria, collectively called nitrifiers, consist of the genera Nitrosomonar and Ntro- bacter. The oxidation of ammonia to nitrate is considered ...
How did the Spanish-American War lead to the Filipinos rebelling against the United States?
How did the Spanish-American War lead to the Filipinos rebelling against the United States?...
The Royal Fruit Company produces two types of fruit drinks. The first type is 70% pure fruit juice, and the second type is 95% pure fruit juice. How many pints of each drink must be used to make 50 pints of a mixture that is 90% pure fruit juice?
The Royal Fruit Company produces two types of fruit drinks. The first type is 70% pure fruit juice, and the second type is 95% pure fruit juice. How many pints of each drink must be used to make 50 pints of a mixture that is 90% pure fruit juice?...