Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please read instructions carefully, thanks. Will give thumbs up #1 [4 points] Pa

ID: 3886705 • Letter: P

Question

Please read instructions carefully, thanks. Will give thumbs up

#1 [4 points] Part A: Working with float vector using Array A class FloatVectArray has been declared and needs to be implemented using an array of type float to set its elements. First, complete the class by finishing the code for the default and copy constructors the assignment operator and the destructor. Then use the main function to test it. #include using namespace std class FloatVectArray public: nt vsize-10) loat vlist, int arraysize):1 eonstructor with inis pazaneter onst EloatVectArrayEva)i copy constructor operator default constructor FloatVectAr ray& (const FloatVectArrays fva); ,, azzgennz: op-nra to: . destructor :/ prints all elements in the vector private: float vector; int vectorsize/ size of the vector the vector l: default constructor To be completed I constructor with initialization parameters loatyctaiFloatVecthrraylfloat vlist[l. int arraysize) i To be completed copy constructor laatycav1oatVectArray(const PloatVectArray& fva) o be completed // assignment operator FloatVectArraysLoatVctaioperator -(const FloatVectArray sfva) To be completed destzuctor To be completed void 2loatWetAraiprintElements To be completed

Explanation / Answer

Hi,
here is the full code with all subparts solved, for the second question you will have to post separate as chegg doesnt allow us to answer more than one question in a single answer.

#include <iostream>

using namespace std;

class FloatVectArray {

public:

FloatVectArray(int vsize = 10); // default constructor

FloatVectArray(float vlist[], int arraysize); // constructor with init parameters

FloatVectArray(const FloatVectArray& fva); // copy constructor

FloatVectArray& operator = (const FloatVectArray& fva); // assignment operator

~FloatVectArray(); // destructor

void printElements(); // prints all elements in the vector

private:

float *vector; // the vector

int vectorsize; // size of the vector

};

// default constructor

FloatVectArray::FloatVectArray(int vsize) {

vectorsize=vsize;

}

// constructor with initialization parameters

FloatVectArray::FloatVectArray(float vlist[], int arraysize) {

// To be completed   
vector=vlist; //setting values
vectorsize=arraysize;

}

// copy constructor

FloatVectArray::FloatVectArray(const FloatVectArray& fva) {

vector = fva.vector; //setting values
vectorsize = fva.vectorsize;

}

// assignment operator

FloatVectArray& FloatVectArray::operator = (const FloatVectArray &fva) {

// To be completed   
if(this != &fva) //checking if not the same object
vector = fva.vector;
vectorsize=fva.vectorsize;
return *this;
}

// destructor

FloatVectArray::~FloatVectArray() {

// To be completed   
if(vector) //checking if already allocated
delete []vector;
}

void FloatVectArray::printElements() {

// To be completed   
for(int i=0;i<vectorsize;i++)
cout<<vector[i]<<" ";
}

int main() {

// testing the implementation of a float vector using array

// declare & initialize an array of floats and create a float vector aVect

float FloatArray1[10] = {2.1, 7.2, 3.3, 6.4, 1.5, 43.6,72.7,19.8,39.9, 71.1};

FloatVectArray aVect(FloatArray1, 10);

cout << "Printing all elements in aVect:" << endl;

aVect.printElements();

// declare & initialize another array of floats and create float vector bVect

float FloatArray2[10] = {1.1, 2.2, 5.3, 6.4, 1.5, 7.6, 9.7,17.8, 92.9, 42.1};

FloatVectArray bVect(FloatArray2, 10);

cout << "Printing all elements in bVect:" << endl;

bVect.printElements();

// try the assignment constructor

bVect = aVect;

cout << "Assigned bVect = aVect. Printing now all elements in bVect:" <<endl;

bVect.printElements();

// try the copy constructor

FloatVectArray cVect = aVect;

cout << "cVect is a copy of aVect. Printing all elements in cVect:" << endl;

cVect.printElements();


return 0;

}

Thumbs up if this was helpful, otherwise let me know in comments. Good Day

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote