1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
//main.cpp//
// INCLUDE FILES
#include <iostream>
#include <iomanip>
#include "vector.h"
using namespace std;
int main() {
// 1. Declare three vector objects A, B, C with the values [1.0,0.0,0.0] , [0.0,1.0,0.0] and [0.0,0.0,1.0] respectively.
Vector A(1.0, 0.0, 0.0),
B(0.0, 1.0, 0.0),
C(0.0, 0.0, 1.0);
cout.precision(3);
cout << fixed;
cout << "1. Three Vectors: A, B, & C." << endl;
// 2. Display the three vectors.
cout << "2. A = " << A << " = " << A.magnitude() << endl;
cout << " B = " << B << " = " << B.magnitude() << endl;
cout << " C = " << C << " = " << C.magnitude() << endl;
// 3. Display the dot product of A and B.
cout << "3. A * B = " << A * B << endl;
// 4. Display the cross product of A and B.
Vector crossAB = A ^ B;
cout << "4. A ^ B = " << crossAB << " = " << crossAB.magnitude() << endl;
// 5. Display the cross product of B and A (The cross product is not commutative,
// you should get a different answer than you got for test 4.)
Vector crossBA = B ^ A;
cout << "5. B ^ A = " << crossBA << " = " << crossBA.magnitude() << endl;
// 6. Perform the assignment statement, A = A * 3.27; and then display the value and magnitude of vector, A.
A = A * 3.27;
cout << "6. A = " << A << " = " << A.magnitude() << endl;
// 7. Perform the assignment statement, B = 4.5 + B; and then display the value and magnitude of vector, B.
B = 4.5 + B;
cout << "7. B = " << B << " = " << B.magnitude() << endl;
// 8. Perform the assignment statement, C = C 1.36; and then display the value and magnitude of vector, C.
C = C - 1.36;
cout << "8. C = " << C << " = " << C.magnitude() << endl;
// 9. Declare vector, D(A B), and display D.
Vector D(A - B);
cout << "9. D = " << D << " = " << D.magnitude() << endl;
// 10. Display A and B to ensure that their values didn't change.
cout << "10. A = " << A << " = " << A.magnitude() << endl;
cout << " B = " << B << " = " << B.magnitude() << endl;
// 11. Declare vector, E(B + C), and display E.
Vector E(B + C);
cout << "11. E = " << E << " = " << E.magnitude() << endl;
// 12. Display B and C to ensure that their values didnt change.
cout << "12. B = " << B << " = " << B.magnitude() << endl;
cout << " C = " << C << " = " << C.magnitude() << endl;
// 13. Display the dot product of D and E.
cout << "13. D * E = " << D * E << endl;
// 14. Display D and E to ensure that their values didnt change.
cout << "14. D = " << D << " = " << D.magnitude() << endl;
cout << " E = " << E << " = " << E.magnitude() << endl;
// 15. Display the cross product of D and E.
Vector crossDE = D ^ E;
cout << "15. D ^ E = " << crossDE << " = " << crossDE.magnitude() << endl;
// 16. Display D and E to ensure that their values didnt change.
cout << "16. D = " << D << " = " << D.magnitude() << endl;
cout << " E = " << E << " = " << E.magnitude() << endl;
// 17. Perform the unary negation operator on vector E and then display it
Vector negE = -E;
cout << "17. -E = " << negE << " = " << negE.magnitude() << endl;
// 18. A Unit vector is a vector that points in the same direction as the original vector,
// but whose magnitude is unity (1). It is calculated by dividing the vector by its magnitude
// (e.g., VectorA/VectorA.mag()). Calculate and display the Unit vector for E.
Vector unitE = E / E.magnitude();
cout << "18. Unit vector of E = " << unitE << " = " << unitE.magnitude() << endl;
// 19. Display the result (i.e., true or false NOT 1 or 0) of the operation, A = = B.
cout << "19. A == B = " << ((A == B) ? "true" : "false") << endl;
// 20. Display the result (i.e., true or false NOT 1 or 0) of the operation, D < E.
cout << "20. D < E = " << ((D < E) ? "true" : "false") << endl;
// 21. Perform the cascaded assignment A = B = C = Vector(1.5, 2.5, 3.5); and then display all of
// these vector objects to verify they are indeed equal.
A = B = C = Vector(1.5, 2.5, 3.5);
cout << "21. A = " << A << " = " << A.magnitude() << endl;
cout << " B = " << B << " = " << B.magnitude() << endl;
cout << " C = " << C << " = " << C.magnitude() << endl;
return(0);
}
|