Lab 0: Practice with C++
CS 445 Computer Graphics, Fall 2014


Due Date: The end of lab on Tuesday, Sept 2

Goals

  1. Familiarize yourself with Codeblocks (or whatever IDE you prefer using)
  2. Familiarize yourself with the main differences between Java and C++
  3. Practice declaring arrays and objects, creating classes, passing parameters, pointers, etc

Note, this course is not a course in c++ and so it is not expected to give you a thorough and in-depth understanding of the language. Instead, we will focus primarily what you will need to do the assignments. However, you are encouraged to dig into the language as much as you can. Many references are provided below and there are many more available online. Your textbook was chosen because it provides many examples of how to use the language. These examples will be invaluable when you find yourself staring at code wondering why your syntax is not correct and what you are doing wrong. However, to get started, you may be better off reading through some of the simpler explanations in the other references below.

Resources

It isn't Java

Compilation process: simple and slightly more detail .

Since you know how to program in Java, much of C++ will be familiar. However, there are some crucial differences. Concepts that may be new include

The following concepts should be familiar but will trip you up because of the slightly different syntax or because the way they are handled in regard to memory, pointers, reference passing:

Practice

To Hand In

Download and run this Codeblocks project which contains a class for storing RGB colors. Note the use of overloaded operators. Add code to test more of the RGBColor functions.

Once you are convinced you understand how RGBColor is implemented, add a second class to the project: Vector3D.h and Vector3D.cpp which stores 3 float values x, y, and z. (These files are already in the project folder and are partially implemented - you just need to add them to the project and finish the implementation. If you want to challenge yourself, start from scratch!) The following functions should be implemented:

Vector3D(void);                                 // default constructor
Vector3D(double a);                             // constructor
Vector3D(double _x, double _y, double _z);      // constructor
Vector3D(const Vector3D& v);                    // copy constructor
~Vector3D (void);                               // destructor
Vector3D& operator= (const Vector3D& rhs);      // assignment operator
Vector3D operator- (void) const;                // unary minus
double length(void);                            // length
double len_squared(void);                       // square of the length
Vector3D operator* (const double a) const;      // multiplication by a double on the right
Vector3D operator/ (const double a) const;      // division by a double
Vector3D operator+ (const Vector3D& v) const;   // addition
Vector3D& operator+= (const Vector3D& v);       // compound addition
Vector3D operator- (const Vector3D& v) const;   // subtraction
double operator* (const Vector3D& b) const;     // dot product
Vector3D operator^ (const Vector3D& v) const;   // cross product
void normalize(void);                           // convert vector to a unit vector
Vector3D& hat(void);                            // return a unit vector, and normalize the vector

Demonstrate your program in lab no later than the end of lab on Tues, Sept 2. Zip together the entire Codeblocks project (minus the obj and bin folders) and submit via WISE assignments. If you are not using Codeblocks, then zip together all of your source code.

Remember: Assignments are due by the end of lab on the due date. Assignments turned in after this are considered late. Assignments that are late by 1 week or less are penalized by 25%, and by 50% after that. (Note, if lab time runs out before you can demo your program, then be sure to submit your code to wise on time and demo as soon as possible. In this case you won't incur a late penalty)