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


Due Date: The 5pm on Tuesday, Sept 4

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

Resources

See the Codeblocks and C++ links on the Links Page:

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 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 5pm on Tues, Sept 4. Zip together the project and submit via WISE assignments. If you are not using Codeblocks, then you must zip together all of your source code.

Remember: late assignments will be penalized by 25% if they are not turned in by the time & day they are due, and 50% if they are more than 1 week late.