#include "stdstuff.h" #include "Vector.h" void realMain () { Vector force, r, moment, direction, totalForce (0, 0, 0), totalMoment (0, 0, 0); int forceCount; cout << "Enter number of forces: "; cin >> forceCount; for (int i = 0; i < forceCount; i++) { cout << "Enter i, j, and k for force: "; force.read (cin); cout << "Enter i, j, and k for point of application: "; r.read (cin); // totalForce = totalForce + force totalForce.add (force); // moment = r X force (cross product) moment = r.cross (force); // totalMoment = totalMoment + moment totalMoment.add (moment); } cout << "The forces are equivalent to the combination of\n 1/. A force of "; totalForce.write(cout); cout << " applied at the origin and\n 2/. A moment of "; totalMoment.write(cout); cout << ".\nThe magnitude of the force is " << totalForce.magnitude() << ".\n"; cout << "\nEnter i, j, and k for the direction of interest: "; direction.read(cin); try { // convert the vector entered to a unit vector in the same direction direction.unitize (); // compute and output totalForce . direction (the dot product) cout << "The magnitude of the force in this direction is " << totalForce.dot (direction) // dot product << ".\n"; } catch (domain_error &e) { // method "unitize" throws a domain_error exception if // applied to 0i + 0j + 0k. // if we get here, this must have happened. cout << "An all zero vector has no direction.\n"; } } int main () { try { realMain (); } catch (exception &e) { // catches all uncaught exceptions cout << "\nException <" << e.what() << "> occurred.\n"; } pause (); return 0; }