CSE 333 25sp Exercise 10

out: Monday, April 28, 2025
due: Wednesday, April 30, 2025 by 10:00 am, No late exercises accepted.

Goals: Create a modified version of the Vector type from the previous exercise using dynamic memory allocation and friend functions this time. Learn how to use C++ dynamic memory management operations new and delete.

Description: Create a C++ class Vector that implements 3-D vectors and has almost the same specification as the Vector class from the previous exercise, but this time does not include the get_x, get_y, and get_z accessor functions from before, and that uses a different representation for the data as described below.

Hints: Some of the functions we need to implement, such as vector multiplication and stream output, need access to the instance variables of a vector even though no access functions like get_x() are included in the class this time. Instead, declare inside the class that these external routines are friend functions. For example, inside class Vector:

  // dot-product: if a is (a,b,c) and b is (x,y,z),
  // return ax+by+cz
  friend double operator*(const Vector &a, const Vector &b);
The actual overloaded operator* function is then declared and implemented as a separate ordinary function in the same namespace as the class, but it can access private details of its Vector parameters.

You may find it helpful to start with your code or the sample solution from the previous exercise (ex9) and modify it as needed to use the new array representation for the Vector data and make other necessary changes.


Your code must:

You should submit your exercise using the Gradescope dropbox linked on the course resources web page.