Before next class:
Before next Thursday:
postmortems. This is worth a Blugold. Log in to the blog using the Login link in the menu at the top of the page. You should have received an email with your password earlier this week. Check your junk mail if you can’t find it, or go through the Forgot my Password dance.
Pair up with a neighbor to write a
Vector3 class with the following specification:
floats to represent the vector’s three components.
operator) that accepts an index of 0, 1, or 2. When the index is 0, it returns the x-component. 1, the y-component. 2, the z-component. So that this message may serve as both a getter (
cout << v) and a setter (
v = 1.2f) return the
floatas a reference to a member variable.
constmethod that determines the dot product of this vector and a parameter vector (which comes in as a
+method that adds component-wise this vector to a parameter vector and returns the sum as a new vector.
+=method similar to the previous method but which alters this vector instead of yielding a new one.
*method that scales component-wise this vector by a float scale factor parameter and returns the scaled vector as a new vector.
*=method similar to the previous method but which alters this vector instead of yielding a new one.
Declare the class in
Vector3.h. Define it in
Vector3.cpp. Create these files through Windows Explorer in the top-level source directory.
Many students prefer editing in Notepad++. You may make your edits with it, and when you go to run your projects, jump to Visual Studio. Messy, huh? I prefer the workflow of Linux or Mac.
Also write a
<< method for printing vectors. Note that this can’t be a member of
Vector3, since the invoking object will be an
ostream, not a
Now let’s create a second project in our Git repository for testing your
Vector3 class. Create a directory named
vectest and create file
vectest.cpp with a
main function that creates some vectors, scales them, adds them, and prints them. Invoke every method you wrote and make sure it does the correct thing.
first/CMakeLists.txt to your
vectest directory. Change all the
first references to
../Vector3.cpp to the
add_executable command. Also, in order to make CMake aware of this new project, add this line to the overall
CMakeLists.txt in your top-level source directory:
Rebuild in Visual Studio.
Add your new files to your Git project using the GUI client and push them to Bitbucket.