Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- struct vect
- {
- double x,y;
- };
- void add(vect &a, vect &b);
- void subtract(vect &a, vect &b);
- void multiply(vect &a, vect &b);
- void scalarProduct(vect &a, vect &b);
- void magnitude(vect &a, vect &b);
- int main()
- {
- int o;
- vect a, b;
- cout << "Please enter the x value for the first vector: ";
- cin >> a.x;
- cout << "Please enter the y value for the first vector: ";
- cin >> a.y;
- cout << "Please enter the x value for the second vector: ";
- cin >> b.x;
- cout << "Please enter the y value for the second vector: ";
- cin >> b.y;
- do
- {
- cout << "What would you like to do:\n1. Add\n2. Subtract\n3. Multiply\n4. Find the scalar product\n5. Find the magnitude\n";
- cin >> o;
- switch(o)
- {
- case 1: add(a,b);
- break;
- case 2: subtract(a,b);
- break;
- case 3: multiply(a,b);
- break;
- case 4: scalarProduct(a,b);
- break;
- case 5: magnitude(a,b);
- break;
- }
- }
- while( o <= 5 && o >= 1 );
- return 0;
- }
- void add(vect &a, vect &b)
- {
- cout << "(" << a.x + b.x << "," << a.y + b.y << ")" << endl;
- }
- void subtract(vect &a, vect &b)
- {
- cout << "(" << a.x - b.x << "," << a.y - b.y << ")" << endl;
- }
- void multiply(vect &a, vect &b)
- {
- cout << "(" << a.x * b.x << "," << a.y * b.y << ")" << endl;
- }
- void scalarProduct(vect &a, vect &b)
- {
- cout << (a.x * b.x) + (a.y * b.y) << endl;
- }
- void magnitude(vect &a, vect &b)
- {
- int i;
- cout << "Which vector would you like to know the magnitude of?\n1: (" << a.x << "," << a.y << ")\n2: (" << b.x << "," << b.y << ")\n";
- cin >> i;
- switch(i)
- {
- case 1: cout << sqrt((a.x*a.x) + (a.y*a.y)) << " or √" << (a.x*a.x) + (a.y*a.y) << endl;
- break;
- case 2: cout << sqrt((b.x*b.x) + (b.y*b.y)) << " or √" << (b.x*b.x) + (b.y*b.y) << endl;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement