Due Date: The 5pm on Tuesday, Sept 4
See the Codeblocks and C++ links on the Links Page:
It is assumed that, over the summer, you reviewed some of the differences between Java and C++, eg see Programming Abstractions in C++, Roberts & Zelenski. Use this (or whatever book/website you like) as a reference while you do this lab. In the instructions here, page numbers will refer to the Roberts & Zelenski document. Page 6, for example, shows the structure of a C++ program.
Begin by creating a new project of type "console application" in codeblocks. Build and run the program (main.cpp). Compare this to the basic structure of a C++ program given on p. 6.
In class, we will practice declaring and manipulating strings and pointers. Try this on your own. Does it make sense?
Skim through and try implementing these (we will do some in class):
In class, we will go over writing functions:
In class, we will go over writing classes and creating objects. Also see p. 341, classses and Deitel & Deitel. We will see much more of c++ classes when we cover ray tracing.
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.