Question: Write a program that performs a variety of vector math operations. These operations include adding vectors, subtracting vectors, and finding the magnitude of a vector.
Write a program that performs a variety of vector math operations. These operations include adding vectors, subtracting vectors, and finding the magnitude of a vector.
Requirements:
- The program should have a clear and easy-to-use interface.
- The program should use only arrays to represent the vectors and assume type double.
- Other built in types like ArrayLists, LinkedLists, etc will result in a 0 for this assignment.
- The program should prompt the user for the size of the vector(s) for each operation(s).
- The program should ask the user to enter the values of the vectors for all operations.
- The program should print out the results of each operation.
- If the user inputs an invalid size for a vector (less than or equal to 0), then the program should prompt the user the size is invalid and stop the operation. However, it should not stop the program.
- The program should keep going until the user chooses to quit.
Example Dialog:
Welcome to the Vector Operations Program!
Enter 1. To Add 2 Vectors
Enter 2. To Subtract 2 Vectors
Enter 3. To Find the Magnitude of a Vector
Enter 9. To Quit
1
Enter the size of the Vectors
3
Enter values for Vector1
1.0
2.0
3.0
Enter values for Vector2
4.0
5.0
6.0
Result:
1.0
2.0
3.0
+
4.0
5.0
6.0
=
5.0
7.0
9.0
Enter 1. To Add 2 Vectors
Enter 2. To Subtract 2 Vectors
Enter 3. To Find the Magnitude of a Vector
Enter 9. To Quit
2
Enter the size of the Vectors
3
Enter values for Vector1
1.0
2.0
3.0
Enter values for Vector2
4.0
5.0
6.0
Result:
1.0
2.0
3.0
-
4.0
5.0
6.0
=
-3.0
-3.0
-3.0.
Enter 1. To Add 2 Vectors
Enter 2. To Subtract 2 Vectors
Enter 3. To Find the Magnitude of a Vector
Enter 9. To Quit
3
Enter the size of the Vector
5
Enter values for the Vector
1.0
2.0
3.0
4.0
5.0
The magnitude is: 7.416198487095663
Enter 1. To Add 2 Vectors
Enter 2. To Subtract 2 Vectors
Enter 3. To Find the Magnitude of a Vector
Enter 9. To Quit
2
Enter the size of the Vectors
0
Invalid Size
Enter 1. To Add 2 Vectors
Enter 2. To Subtract 2 Vectors
Enter 3. To Find the Magnitude of a Vector
Enter 9. To Quit
9
Goodbye!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
