This week's project is a team project to add more functionality to the Vec class we built in this week's lab. To illustrate, suppose that v1, v2, and v3 are Vec objects containing the following values:
v1 == {1, 2, 3}
v2 == {2, 4, 6}
v3 == {1, 2, 3}
Item it = v[i];just like the getItem(i) method we built in the lab exercise, but without any bounds checking on the index value i.
v[i] = it;just like the setItem(i, it) method we built in the lab exercise, but without any bounds checking on the index value i.
v1 != v2should return true. The expression:
v1 != v3should return false.
v3.readFrom(fileName);should fill v3 with values stored in fileName. You may assume that the first thing on the first line of fileName is an integer that specifies the number of values in the file, as shown in the test-files vecTest1.txt and. vecTest2.txt. Be careful that your method does not leak memory!
The expression:
v3.writeTo(fileName);should write all of the values in v3 to the file named by fileName, one per line. The first line of fileName should indicate the number of values in the file.
v3 = v1 + v2;should set v3 == {3, 6, 9}, without leaking memory.
v3 = v1 - v2;should set v3 == {-1, -2, -3}, without leaking memory.
double dProd = v1 * v2;should set dProd == 28. For two vectors u = {u1, u2, ..., uN} and v = {v1, v2, ..., vN},
As indicated on the grade sheet, one member of your team is responsible for the !=, readFrom(), and - operations; the other team member should build the writeTo(), +, and * operations. See me for the teams.
The opening documentation in each file should clearly indicate who wrote which methods.
To make life easier for you, VecTester contains a test-method for each of these operations. Use these test-methods and test driven development to build your operations. If you get your program to compile, but it fails a test and you cannot figure out what is wrong, use the debugger! If necessary, draw a memory diagram and trace through the execution of the problematic function one statement at a time, until you identify the logic error.
Application. Vectors can be used to store positions and/or directional forces in a coordinate system. Vectors of length 2 can be used to store 2-dimensional (x, y) information; vectors of length 3 can be used to store 3-dimensional (x, y, z) information; and so on. When you have "finished" your Vec class, your time is to write a program that
v1 = {1, 0, 0}
v2 = {0, 1, 0}
v3 = {0, 0, 1}
the program should let the user enter these values and then display their sum {1, 1, 1},
which represents the user's final position within the 3-dimensional system.