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. Normally, the subscript operation does not perform bounds checking on the index value i, but yours should perform bounds checking. More precisely, your subscript operator should throw a range_error if it is passed a "bad" index value.
v[i] = it;just like the setItem(i, it) method we built in the lab exercise. As with the other version, this subscript operation does not normally perform any bounds checking on the index value i, but yours should throw a range_error if it receives a bad index value.
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.
Congratulations! You have been named the navigation officer on the starship U.S.S. Boobyprize, whose hyper-spatial engines allow the ship and its crew to explore the universe. Current theories suggest that reality consists of 11 or more dimensions, so you need a program to help you navigate through an N-dimensional space.
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 task is to write a program that:
{1, 0, 0}
{0, 1, 0}
{0, 0, 1}
{1, 2, 3}
the program should then display
the starting position ({0,0,0})
and the sum from the accumulator ({2, 3, 4}),
which is the user's final position within the 3-dimensional system.
As another example, if the user is navigating through a 5-dimensional space, enters {1, 0, 1, 0, 1} as the starting point, and enters three 5-dimensional relative-positions:
{0, 1, 0, 1, 0}
{2, 2, 2, 2, 2}
{-3, -3, -3, -3, -3}
the program should then display the starting position
and the final position ({0, 0, 0, 0, 0}).
You may (if you wish) have your program display the starship's new position each time it is updated, rather than just displaying the final position at the end.
Your application should have the user enter the vectors in the format expected by your readFrom(istream&) method: numbers separated by whitespace. (It does not have to parse through curly-brace and comma characters.) Likewise, your application can display the starship's position using the format provided by your writeTo(ostream&) method -- numbers separated by spaces.
Create a script file in which you use ls to list all your project's files, use cat to display the contents of each file, build your program to demonstrate that it is free of syntax errors, and then run your project to demonstrate that it works correctly. Make certain that your script file is located in your project folder.
Our grader will grade your submission based on the categories given in this grade sheet, so you should make certain all of those categories are covered.