Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

combine DMA and operator overloading to make a container that behaves like a vector (in the mathematical sense) of arbitrary size. You must create a

combine DMA and operator overloading to make a container that behaves like a vector (in the mathematical sense) of arbitrary size. You must create a class called DoubleContainer that has a dynamically allocated array of double values called "content". Your DoubleContainer should also have two int values to store the maximum size of the container as well as the current number of doubles in the container. The container should also have the following public functions:

  • Add(double) - a function that does not return a value, but adds the given double value to the end of the content array
  • Clear() - a function thatdoes not return a value, but removes all doubles from the content array
  • Remove() - a function thatremoves the last double from the content array andreturns it to the caller.

The DoubleContainer class should also have three constructors:

  • A default constructor that initializes the content array to size 5.
  • A constructor that takes in an array of double values, and the size of that array and then initializes the content array to a deep copy of that array.
  • A copy constructor that takes in another DoubleContainer and creates adeep copy of that DoubleContainer.

The DoubleContainer must have overrides for the following:

  • The << operator, which prints the contents array as a comma separated list surrounded by triangle brackets ("<" and ">")
  • The addition operator (+), which takes in two DoubleContainers and creates a new DoubleContainer that represents the componentwise addition of the two. (This is the same as the + operator overload in assignment 3, but will have an arbitrary number of components rather than just 2).
  • The subtraction operator (-), which takes in two DoubleContainers and creates a new DoubleContainer that represents the componentwise subtraction of the later from the former. (This is the same as the - operator overload in assignment 3, but will have an arbitrary number of components rather than just 2).
  • The negation operator(-), which takes in a DoubleContainer and reverses the sign of all the values in the content array for that DoubleContainer.
  • The multiplication operator (*), which takes in a double and a DoubleContainer (in any order) and returns a DoubleContainer whose entries in the content array are the multiplication of the original element and the provided double value.
  • The multiplication operator (*), which takes in two DoubleContainers and returns the dot product of the two content arrays.

Must be in C++

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

Students also viewed these Programming questions

Question

Distinguish a flexible exchange rate from a fixed exchange rate.

Answered: 1 week ago