Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am struggling on completing the assignment and could use the help I thought I had completed it but apparently I did it incorrectly. /

I am struggling on completing the assignment and could use the help I thought I had completed it but apparently I did it incorrectly.

/ Our implementation of a vector (simplified) template class DynArray {

// Gives access to test code friend class DSA_TestSuite_Lab1;

// Data members Type* mArray; // The dynamic array that will be managed within the class size_t mSize; // The number of elements currently storing valid data size_t mCapacity; // The total number of elements available in the currently allocated array static const size_t DEFAULT_CAPACITY = 10; public:

// Default constructor // Creates an empty object // // In: _startingCap An initial size to start the array at // // Note: Do not allocate any memory if the _startingCap is 0 DynArray(size_t _startingCap = DEFAULT_CAPACITY) { // TODO: Implement this method

// Destructor // Cleans up all dynamically allocated memory ~DynArray() { // TODO: Implement this method delete[]mArray; }

// Copy constructor // Used to initialize one object to another // In: _da The object to copy from DynArray(const DynArray& _copy) : mArray(nullptr) { // TODO: Implement this method if() }

// Assignment operator // Used to assign one object to another // In: _da The object to assign from // // Return: The invoking object (by reference) // This allows us to daisy-chain DynArray& operator=(const DynArray& _assign) { // TODO: Implement this method }

// Clear // Cleans up all dynamically allocated memory // Sets all data members back to default values void Clear() { // TODO: Implement this method }

// Overloaded [] operator // Used to access an element in the internal array (read-only) // In: _index The index to access at // // Return: The item at the specified index (by reference) const Type& operator[](int _index) const { // TODO: Implement this method }

// Overloaded [] operator // Used to access an element in the internal array (writeable) // In: _index The index to access at // // Return: The item at the specified index (by reference) Type& operator[](int _index) { // TODO: Implement this method }

// Get the current number of elements actively being used // // Return: The current number of elements used size_t Size() const { // TODO: Implement this method }

// Get the current capacity of the internal array // // Return: The capacity of the array size_t Capacity() const { // TODO: Implement this method }

// Add an item to the end of the array // Should resize the array if needed // // In: _data The item to be added void Append(const Type& _data) { // TODO: Implement this method }

// Resizes the internal array, and copies all data over // In: _newCapacity The new capacity of the array // NOTE: If 0 is passed, the array should double in size // If _newCapacity < mCapacity, do nothing // // SPECIAL CASE: If mCapacity is 0, then it should be set to 1 void Reserve(size_t _newCapacity = 0) { // TODO: Implement this method } };

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_2

Step: 3

blur-text-image_3

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

a. How will the leader be selected?

Answered: 1 week ago