Project I:
Matrices, Vectors, and Multiplication of them.
Your Project must be able to do the following:
You will be responsible for this project in groups of two people. You must comment all your code effectively so that I can follow what you are doing in them.
Points: 100
Due Date: January 27, 1998.
Since in this project one, I am going to help you get started. You will get less help on your other projects.
First, lets design some classes:
class Point3D{
public:
Point3D();
Point3D(double xValue, double yValue, double zValue);
Point3D(Point3D &pt);
~Point3D();double x;
double y;
double z;
};
class Vector{
public:
Vector();
Vector(double a, double b, double c, double d);
Vector(Vector &vector);
Vector(Point3D &pt); // create v={x,y,z,1}
~Vector();double v[4];
};
class Matrix{
public:
Matrix();
Matrix(double a, double b, double c, double d,double e, double f, double g, double h,
double i, double j, double k, double l,
double m, double n, double o, double p);Matrix(Matrix &mat);
~Matrix();double matrix[4][4];
};
This is a good start for all the classes. Begin by implementing these structures before continuing.
Now, that you have that done, lets do the input and output. Well, for input you can get read the input with cin and store the values, since they are public values. To output, lets design a Print routine for each class:
void Print(fstream &file);
or we can overload the << operator for stream output by adding this to the class:
friend ostream& operator<< ( ostream& os, Point3D &pt );
and then the function would be(outside of the class):
ostream& operator<< ( ostream& os, Point3D &pt ){
os << "(" << pt.x << "," << pt.y << "," << pt.z << ")";
return os;
}
Do one or the either for each of the classes. Be sure not to output a newline with the print statements!
For the Point3D class we are done.
For Vector, we need to add:
Vector * Add(Vector &vec);
Which adds this to vec and returns the result when you cann Add.
We also need a subtract function, done the same way, but does this vec.
We also need the following functions:
void Normalize(void); //normalize this = this/||this||
//You should ignore the v[3]s value!
double DotProduct(Vector &vec); //this· vec
Vector * CrossProduct(Vector &vec); //this x vec
For the Matrix class you will need:
Matrix * MultiplyM(Matrix &mat); //computes this * mat
Vector * MultiplyV(Vector &vec); // computes this * vec
Ok, here is what the main program should do: