#include #include #include #include "vec.h" using namespace std; int main() { vec x(1, 0, 0); vec y(0, 1, 0); vec z(0, 0, 1); vec sum = x + y; cout << "The sum of x and y is "; sum.print(); cout << ".\n"; cout << "The midpoint of x and y is "; (sum / 2).print(); //division has lower precedence than dot cout << ".\n"; double dot = x * y; cout << "The dot product of x and y is " << dot << ".\n"; double theta = acos(dot / (x.length() * y.length())); //in radians const double pi = 4 * atan2(1, 1); cout << "The angle between x and y is " << theta / pi << "pi radians or " << theta * 180 / pi << " degrees.\n"; vec perpendicular = x ^ y; cout << "A vector perpendicular to x and y is "; perpendicular.print(); cout << ".\n"; if ((x ^= y) != z) { cerr << "Error: new value of x should be z.\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; }