Question
Working with char vector using Array The class FixedVector has been declared and was implemented. The code is available here. You want to use additional
Working with char vector using Array
The class FixedVector has been declared and was implemented. The code is available here. You want to use additional operations within the class, so the function member insert needs to be changed, as well as two new functions members, find and operator == need to be added to the class definition and implemented. Consider the new class definition below, and the new/modified functions being in bold.
// Augmented Declaration template
size_t find(const T& value); size_t insert(size_t beforeIndex, const T& value); size_t size(); bool empty(); void clear();
// Overloaded Operators FixedVector& operator= (const FixedVector& rhs); //Copy assignment
bool operator== (const FixedVector& rhs) };
// Function member to look for value in FixedVector
// If value is in the FixedVector, then return the index of FixedVector that contains // the value. If size_ is 0 (array is empty) or the value is not in FixedVector, then
// return size_
template
size_t FixedVector
// to be completed
}
// Function member to insert value in the FixedVector at index beforeIndex and return // beforeIndex
// If beforeIndex is between 0 and size_, then insert the value by pushing all the // elements to the right of beforeIndex one position to the right, and increment size_
// If size would exceed capacity, then exit with an error
// If beforeIndex is >=size_ then display error and do not do any changes to FixedVector
template
size_t FixedVector
// to be completed
}
// Function member to test the equality between two FixedVectors
// It returns true if the two FixedVectors are exactly the same, false otherwise
template
bool FixedArray
}
int main() {
// testing the new implementation of a FixedVector
// declare & initialize a FixedVector of int with 10 elements
FixedVector
// place 1,5,10 in the array
cout << FixedArray gets the elements 1, 5, 10 << endl;
Array1.push_back(1);
Array1.push_back(5);
Array1.push_back(10);
// Try the find operation
cout << Value 5 is at index << Array1.find(5) << endl;
// Try the insert operation
cout << Value 2 is inserted at index << Array1.insert(1, 2) << endl;
// Try the == operator
FixedVector
Array2.push_back(1);
Array2.push_back(5);
Array2.push_back(10);
if (Array1 == Array2)
cout << The two arrays are the same. << endl;
else
cout << The two arrays are different. << endl;
return 0;
}
-
Turn in the complete code, including all of the above to be completed sections.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started