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

Lab 6: Design an Array class to operate on and store any number of floating-poin

ID: 665981 • Letter: L

Question

Lab 6:

Design an Array class to operate on and store any number of floating-point values. Write a constructor to accept the amount of floating-point values to dynamically create and a destructor that performs the necessary cleanup and de-allocation. Write an overloaded operator function to perform addition on 2 objects with the same number of floating-point values. Overload the operator to simply add the corresponding floating-point values between two Array objects. In addition, write an overloaded operator function to perform addition between an Array object and a single floating-point value (add the float to each of the array values). Override the default copy constructor and assignment operator to perform a deep-copy. Lastly, overload the output stream operator to print the state of an Arrayobject. Write a small application, similar to the one shown below, to test your class. As before write your Array class in separate source and header files (.C and .h) and the application in a separate file (lab6.C).

Above, the previous lab is shown. I need help with this week's lab, below.

Redesign your Array class from lab6 as a class template to work with the application below. Due to the g++ compiler, your class declaration and class method definitions must both reside in the header file, Array.h. Do not create a separate Array.C file for your class template. In addition, write your overloaded output stream operator as an inline friend method in the class declaration. Include the class template header file in your application as below.

#include "Array.h"

main()

{

  Array<char> c(3);

  c.setValue(0,'c');

  c.setValue(1,'s');

  c.setValue(2,'c');

  cout << c;

  Array<int> i(3);

  i.setValue(0,1);

  i.setValue(1,2);

  i.setValue(2,5);

  cout << i;

  Array<int> j(3);

  j.setValue(0,10);

  j.setValue(1,20);

  j.setValue(2,50);

  cout << j;

  Array<int> ij;

  ij = i + j;

  cout << ij;

}

The output for this program should be as follows:

Array:

  size: 3

  contents: c s c

Array:

  size: 3

  contents: 1 2 5

Array:

  size: 3

  contents: 10 20 50

Array:

  size: 3

  contents: 11 22 55

Explanation / Answer

Array.cpp #include "Array.h" Array::Array(void) { // cout