Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The class FixedVector has been declared and was implemented. The code is available below: https://github.com/CSUF-CPSC-131-Spring2020/Data-Structures-Code/blob/master/FixedVector.hpp You want to use two new member functions within the

The class FixedVector has been declared and was implemented. The code is available below:

https://github.com/CSUF-CPSC-131-Spring2020/Data-Structures-Code/blob/master/FixedVector.hpp

You want to use two new member functions within the class, search and operator != that need to be added to the class definition and implemented. Consider the new class definition below, and the new/modified functions being in bold and highlighted.

// Augmented Declaration

template

class FixedVector {

private:

size_t size_; // number of elements in the data structure

const size_t capacity_; // length of the array

T* array_; // pointer to dynamically allocated array

public:

// Constructors

FixedVector(size_t arraysize = 0); // Also serves as default constructor

FixedVector(const FixedVector& input ); // Copy constructor

~FixedVector();

// Getters / Setters

T& at(size_t index);

T& operator[](size_t index);

void push_back(const T& value);

void set(size_t index, const T& value);

void erase(size_t index);

size_t search(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::search(const T& value) {

// to be completed

}

// Function member to test the equality between two FixedVectors

// It returns true if the two FixedVectors are not exactly the same, false otherwise

template

bool FixedVector::operator!= (const FixedVector& rhs){

// to be completed

}

int main() {

// testing the new implementation of a FixedVector

// declare & initialize a FixedVector of int with 5 elements

FixedVector Array1(5);

// 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 insert operation

Array1.insert(1, 85);

cout<<"After inserting 85 at index 1, the vector looks like: "<< endl;

for(int i =0; i

cout<

// Try the != operator

FixedVector Array2(5);

Array2.push_back(1);

Array2.push_back(5);

Array2.push_back(10);

if (Array1 != Array2)

cout << "The two arrays are different." << endl;

else

cout << "The two arrays are the same." << endl;

// Try the search operation

//cout<< "Value 5 is at index "<< Array1.search(5) << endl;

return 0;

}

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

2.5 Describe a social audit.

Answered: 1 week ago