Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following header file, implement the functions for a dynamic array that: DynamicArray::DynamicArray() : m_length(0), m_capacity(0), m_scaling_factor(2.0), m_data(nullptr) { } DynamicArray::DynamicArray(double scaling_factor, unsigned int

Given the following header file, implement the functions for a dynamic array that:

DynamicArray::DynamicArray()

: m_length(0), m_capacity(0), m_scaling_factor(2.0), m_data(nullptr) {

}

DynamicArray::DynamicArray(double scaling_factor, unsigned int capacity) {

//..............

// TODO

//..............

}

DynamicArray::DynamicArray(double scaling_factor, unsigned int length, int default_value) {

//..............

// TODO

//..............

}

image text in transcribedimage text in transcribed

#ifndef DYNAMIC_ARRAY_H #define DYNAMIC_ARRAY_H 11 #include class DynamicArray { private: // the number of items currently in the array unsigned int m_length; // the number of available spaces in the array unsigned int m_capacity; 11 the scaling factor when resizing the array (always > 1) double m_scaling_factor; // pointer to the array of integers int *m_data; public: // default constructor, capacity = e, no need to allocate an internal array yet DynamicArray(); // default constructor with a scaling factor, creates an array with capacity = capacity DynamicArray(double scaling_factor, unsigned int capacity); // fill constructor, creates an array of capacity = length, and set all values to 'default_value DynamicArray(double scaling_factor, unsigned int length, int default_value); // copy constructor DynamicArray(const DynamicArray& other); // default destructor, free memory of the array here --DynamicArray(); // get the number of elements in the array unsigned int getLength(); Il get the capacity of the array unsigned int getcapacity(); 1/ get scaling factor Needed by GUI double getscalingFactor(); // set the scaling factor of the array void setscalingFactor (double value); Il convert the vector into a printable string std::string tostring(); Il find the first occurrence of "value" in the array. Return false if the value is not found // (10 points if correct] bool findFirstof(int value, unsigned int* index); // find the last occurrence of "value" in the array. Return false if the value is not found // (10 points if correct] bool findlastof(int value, unsigned int* index); // add a value to the end of the array (resize if necessary) unsigned int getcapacity(); 1/ get scaling factor Needed by GUI double getScalingFactor(); 1/ set the scaling factor of the array void setscalingFactor(double value); 11 convert the vector into a printable string std::string tostring(); Il find the first occurrence of "value" in the array. Return false if the value is not found 11 (10 points if correct] bool findFirstof(int value, unsigned ints index); 1/ find the last occurrence of "value" in the array. Return false if the value is not found // (10 points if correct] bool findlastof(int value, unsigned int* index); // add a value to the end of the array (resize if necessary) // [10 points if correct] void append(int value); // add a value to the beginning of the array (resize if necessary) // (10 points if correct] void prepend(int value); // remove the last value from the array // (10 points if correct] void removeLast(); // remove the first value from the array 11 (10 points if correct] void removeFirst(); // remove all elements from the array // allocated memory should be deleted and the array pointer should now point to NULL Il capacity and length should be reset to zero // (10 points if correct] void clear(); // overloading the [] operator for read/write access int& operator[](unsigned int index); Il assignment operator DynamicArray& operator=(const DynamicArray &other); 76 }; 78 #Endif #ifndef DYNAMIC_ARRAY_H #define DYNAMIC_ARRAY_H 11 #include class DynamicArray { private: // the number of items currently in the array unsigned int m_length; // the number of available spaces in the array unsigned int m_capacity; 11 the scaling factor when resizing the array (always > 1) double m_scaling_factor; // pointer to the array of integers int *m_data; public: // default constructor, capacity = e, no need to allocate an internal array yet DynamicArray(); // default constructor with a scaling factor, creates an array with capacity = capacity DynamicArray(double scaling_factor, unsigned int capacity); // fill constructor, creates an array of capacity = length, and set all values to 'default_value DynamicArray(double scaling_factor, unsigned int length, int default_value); // copy constructor DynamicArray(const DynamicArray& other); // default destructor, free memory of the array here --DynamicArray(); // get the number of elements in the array unsigned int getLength(); Il get the capacity of the array unsigned int getcapacity(); 1/ get scaling factor Needed by GUI double getscalingFactor(); // set the scaling factor of the array void setscalingFactor (double value); Il convert the vector into a printable string std::string tostring(); Il find the first occurrence of "value" in the array. Return false if the value is not found // (10 points if correct] bool findFirstof(int value, unsigned int* index); // find the last occurrence of "value" in the array. Return false if the value is not found // (10 points if correct] bool findlastof(int value, unsigned int* index); // add a value to the end of the array (resize if necessary) unsigned int getcapacity(); 1/ get scaling factor Needed by GUI double getScalingFactor(); 1/ set the scaling factor of the array void setscalingFactor(double value); 11 convert the vector into a printable string std::string tostring(); Il find the first occurrence of "value" in the array. Return false if the value is not found 11 (10 points if correct] bool findFirstof(int value, unsigned ints index); 1/ find the last occurrence of "value" in the array. Return false if the value is not found // (10 points if correct] bool findlastof(int value, unsigned int* index); // add a value to the end of the array (resize if necessary) // [10 points if correct] void append(int value); // add a value to the beginning of the array (resize if necessary) // (10 points if correct] void prepend(int value); // remove the last value from the array // (10 points if correct] void removeLast(); // remove the first value from the array 11 (10 points if correct] void removeFirst(); // remove all elements from the array // allocated memory should be deleted and the array pointer should now point to NULL Il capacity and length should be reset to zero // (10 points if correct] void clear(); // overloading the [] operator for read/write access int& operator[](unsigned int index); Il assignment operator DynamicArray& operator=(const DynamicArray &other); 76 }; 78 #Endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions