Due: Monday, November 25, 2024, at 11:59pm
Goals
Synopsis
Set-Up
Provided Files
Your Task
Assessment
Turn-in instructions
This assignments provides practice with basic C++ functionality, including class defintions, heap memory usage, and namespaces.
You will create a C++ class Vector that implements 3-D vectors. A header file is provided that describes the required functionality for this class, and you will implement each method or function required to support the class. You will use C++ techniques.
Before you get started, ensure that your set-up is up-to-date and appropriate.
cancun
, including g++
git status
to determine if there are outstanding changes, and git add
and git commit
if you are unsure.)git pull upstream main
to pull the newest commit from the upstream repository.
This will give you access to the hw8
folder containing the materials for this
assignment. (upstream
specifies that you want to pull from the upstream
repository, and main
specifies the branch. You may see a text editor open to allow
you to edit the merge message. This will likely be Vim, so you can edit it and then save,
or just accept the current text and exit using :q!
.)You will do this assignment in your new hw8
folder.
You should get into the habit of committing and pushing code frequently.
Your hw8 folder contains the following files:
Vector.h
: Header file describing the Vector Class.hw8.cc
: Client for the Vector class; Runs hw8 demo.Makefile
: A Makefile to compile your code and run the demo.cpplint.py
: The linter you will use to check your coding style.You will create a C++ class Vector
that implements 3-D vectors. This
class will be defined in the file Vector.cc
. You should
not modify any of the starter files provided for this assignment.
In file Vector.cc
implement the Vector
class with the following properties:
Vector
should be an array containing three
floats giving the magnitudes in the x, y, and z directions.
The array should be dynamically allocated on the heap when a Vector
is created and deleted when the Vector
no longer exists.Vector
to (0,0,0), a constructor with 3 floats as parameters giving
initial values for the x, y, and z magnitudes, and a copy constructor.Vector
object is deleted. If no work is needed, the body of
the destructor can be empty.(u=v)
.*
should compute the inner product (dot product)
of two Vectors. If v1=(a,b,c) and v2=(d,e,f), then
v1*v2
should return the scalar value a*d+b*e+c*f.Vector
containing the components of v multiplied by k (i.e., (a*k,b*k,c*k)).s<<v
will write Vector
v to stream s as (a,b,c),
i.e., a left parentheses followed by the x, y, and z components of
v separated by commas, and a right parentheses. There should be no
added spaces in the output. Thereis no std::endl at the end.Vector
class and associated functions should be
placed in a namespace vector374.Note: Pay attention to the data types of the specified
functions. This code makes use of references, and also sometimes requires
returning a Vector
(not a pointer to a Vector
). You should take care to
create your Vector
s and return them appropriately.
You should ensure that your code follows typical guidelines regarding
variable naming. You
may include comments as necessary for any tricky parts of your code. You
will also want to use cpplint.py
to check that your code
complies with the style guidelines before submitting.
This assignment will be worth 40 points. Your code will be evaluated by an autograder. You are welcome to submit again in order to achieve a better score, but, you should use your hw8 exectuble to test your code before you do so. Be sure to fix warnings or errors that occur during compilation, and then compare the ouput of your code to the target output.
You will submit this homework to the Gradescope HW8: C++ Vector Implementation, via Gitlab. You should commit your work to your repository, including your Vector.cc file. These files will be located in the hw8 folder at the top level of your repository.
Once you locate the Gitlab assignment you will tap the "GitLab" button on the bottom:
Once you submit your code the autograder may take some time to run. You may resubmit for a higher grade, but your should always do as much testing as possible on your own platform before resubmitting.