One of the tools you can use within C++ is that of overloading operators.
This is a highly controversial tool in the Object-Oriented community as some
believe it is a dangerous tool while others believe it allows a developer to
use built-in constructs in a reasonable manner. One of the most common
examples of the usefulness of overloading operators is a three-dimensional
vector class. 3D games use these basic vectors as the fundamental basis for
all polygon representations.
Your application must support the following menu of choices and corresponding
actions, with the following integers used to select each:
All input to the system will be of the correct type and will be an
acceptable value
Negation of a 3D Vector
The negation of a vector is simply the negation of each of the dimensions:
-(1.0, -2.0, 3.0)
= (-1.0, 2.0, -3.0)
Length of a 3D Vector
The length of a vector is simply the square root of the sum of the square of
each dimension. The length is simply:
length(a1, a2, a3) = square_root(a1^2 + a2^2 + a3^2)
(Note: the above formula is not valid C++)
Addition of two 3D Vectors
The addition of two vectors is simply the sum of each dimension:
(1.0, 2.0, 3.0) + (0.5, 2.4, 5.1)
= (1.0 + 0.5, 2.0 + 2.4, 3.0 + 5.1)
= (1.5, 4.4, 8.1)
Subtraction of two 3D Vectors
The subtraction of two vectors is simply the difference of each dimension:
(1.0, 2.0, 3.0) - (0.5, 2.4, 5.1)
= (1.0 - 0.5, 2.0 - 2.4, 3.0 - 5.1)
= (0.5, -0.4, -2.1)
Dot Product of two 3D Vectors
The dot product is a scalar (double-precision) value correlates to the cosine
of the angle between the two vectors. The dot product is computed as follows:
(a1, a2, a3) . (b1, b2, b3)
= a1 * b1 + a2 * b2 + a3 * b3
Cross Product of two 3D Vectors
The cross product is a vector that is perpendicular to both of the given
vectors. The cross product is computed as follows:
(a1, a2, a3) x (b1, b2, b3)
= (a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 * b2 - a2 * b1)
Files
You can copy all necessary files from the following directory:
/afs/umbc.edu/users/d/a/dana3/pub/CMSC202/hw2/
makefile
The makefile supplied will allow you to build and test your application. You
will need to alter the makefile to support your 3D Vector class. A macro has
been created to simplify this - in the makefile, look for 'VECTOR', and change
the right-hand side to be the name of your Vector class.
You can use make test to run your application on the supplied input
file. The output should match the example output EXACTLY. You can use diff
exampleOutput.txt output.txt to verify that the files are the same. If
nothing prints to the screen, then the output is identical, otherwise, there
are some differences.
input.txt
This is an example of the input file that your application must work with. It
is NOT a comprehensive testing suite - you should develop your own testing
suite to test your class, but you can use this file as a starting point.
exampleOutput.txt
This is an example of the output that should be produced by your program when
run on input.txt.
Grading
The grade for this homework will be broken down as follows. A more detailed
breakdown will be provided in the grade form you receive
with your homework grade.
85% - Correctness and Design
This list may not be comprehensive, but everything on this list will be
verified by the graders.
- Vector class is designed well including code reuse, high cohesion,
appropriate overloaded operators
- Using const appropriately
- Using friend appropriately
- Output matches requirements
- Reused code to the maximum extent possible
15% - Style and Standards
Your code must adhere to the course coding standards.
Homework Submission
What to Submit
You must submit the following files:
- Your vector class's .cpp file
- Your vector class's .h file
- Hw2.cpp
- makefile
Steps for Submission
- submit all files
- submitls to verify they are in the remote directory
- submitmake to build your files remotely
- submitrun to run the application in your remote directory
Assuming you've used the recommended file names, then
to submit your homework, type the command
submit cs202 Hw2 files ...
The order in which the files are listed doesn't matter. However, you must make
sure that all files necessary to compile your project (using the makefile)
are listed. You need not submit all files at the same time. You may resubmit
your files as often as you like, but only the last submittal will be graded and
will be used to determine if your project is late. For more information,
see the projects page on the course website.
You can check to see what files you have submitted by typing
submitls cs202 Hw2
Be sure to build your project once it has been submitted using the submitmake
command, so that you know that all of the files are there and are the most
up-to-date versions:
/afs/umbc.edu/users/d/a/dana3/pub/CMSC202/submitmake cs202 Hw2
More complete documentation for submit and related commands can be found
here.
Remember -- if you make any change to your program, no matter how
insignificant it may seem, you should recompile and retest your program before
submitting it. Even the smallest typo can cause compiler errors and a reduction
in your grade.
Avoid unpleasant surprises!
Be sure to use the submitmake
utilities provided for you to compile, link and run your program after you've
submitted it.