If an object of class Foo was created in dynamic memory with the `new` keyword, then the Foo class destructor will be activated when `delete` is called on a pointer holding the address of the object.
If an object of class Foo was created and assigned to a variable in the stack, the Foo class destructor will be activated when the variable goes out of scope.
If an object of class Foo was passed by value to a function, then the Foo class destructor will be activated to delete the local copy of the object when the function ends.
The class destructor is only activated when called explicitly, such as: ~Foo(my_foo)
Itβs important to check for self-assignment when implementing the assignment operator for a class.Β Which of the following is a correct check for possible self-assignment?
/*
* addition operator (+)
*
* The x value for the result is the sum of the x values for the two points being added, and
* the y value for the result is the sum of the y values for the two points being added.
* returns a new point that is the sum of two other points
*
* Example: if point1 is (4, -2) and point2 is (3, 1), then
* point1 + point2 will return the point (7, -1)
*/
Write the code to turn the given stub definition for the function into a complete implementation. Note that you will need to use get_x and get_y to reach the values, as the operator is not defined as a friend of the class.
/*
* multiplication operator (*)
*
* Calculates the dot product of two points by adding the product of the x's
* and the product of the y's.
* returns the dot product of two points
*
* Example: if point1 is (4, -2) and point2 is (3, 1), then
* the dot product would be (4 * 3) + (-2 * 1), i.e., 10
*/
Write the code to turn the given stub definition for the function into a complete implementation. Note that this will not be a friend to the class, so you will need to use get_x and get_y to access the member variables values.
/*
* equivalence (==)
*
* Two points are equivalent if they have the same x value and the same y value.
* returns true if point1 and point2 are equivalent; otherwise, returns false
*/
Write the code to turn the given stub definition for the function into a complete implementation. Note that this will not be a friend to the class, so you will have to use get_x and get_y to access the variables.
/*
* input stream operator (>>)
*
* - takes data from the input stream and assigns new values to the
* instance variables of the point
* - returns the 'in' parameter to allow for chaining
*
* Note: The input consists of the following: "(x, y)" where x and y
* are doubles.
*
* Example: If the input stream 'in' holds the message
* "(-1.5, 3.75)"
* then 'in >> pt' will cause pt's data to become
* x: -1.5; y: 3.75
*
Write the code to turn the given stub definition for the function into a complete implementation. This will be a friend to the class, so you can directly write into the x and y variables.
HINT: Be sure to consume all the input, "(x here..., y here...)", including the parentheses, and the comma. You can use the input stream function ignore to skip characters.
/*
* output stream operator (<<)
*
* output a point to a stream
* returns the 'out' parameter to allow for chaining
*
* Note: The output of a point looks like the following:
* "(x, y)"
* where x is the x-value and y is the y-value for the point.
*
* Example: Calling the output stream operator on a point with
* x = 4 and y = -2 would produce the following: (4, -2)
*/
Write the code to turn the given stub definition for the function into a complete implementation.