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

Design an Array class to operate on and store any number of floating-point value

ID: 665569 • Letter: D

Question

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 Array object. 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).

Explanation / Answer

main()
{
Array a1(3);
a1.setValue( 0, 1.0 );
a1.setValue( 1, 22.0);
a1.setValue( 2, 12.2);

Array a2(3);
a2.setValue( 0, 3.3);
a2.setValue( 1, 44.5);
a2.setValue( 2, 21.7);

Array tmp;
tmp = a1 + a2; cout << tmp;
tmp = a1 - a2; cout << tmp;
tmp = a1 * a2; cout << tmp;
tmp = a1 / a2; cout << tmp;

tmp = a1 + 3.0; cout << tmp;
tmp = a1 - 3.0; cout << tmp;
tmp = a1 * 3.0; cout << tmp;

Quote:

}

tmp = a1 / 3.0; cout << tmp;

Quote:

}

Array Array::operator*(const Array &a2)
{
Array tmp(nfloats);

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