This week's project adds 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.
v3 = v1 + v2;should set v3 == {3, 6, 9}, without leaking memory.
v3 = v1 - v2;should set v3 == {-1, -2, -3}, without leaking memory.
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.
To get you well on your way, download App.cpp and App.h. These files provide most of what you have to implement to finish this project.
Create a script file which shows a build of your program -- to demonstrate that it is free of syntax errors, and then a run of your project to demonstrate that it works correctly.
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.
Passes tests | 50 |
operator[] (write version) | 5 |
operator[] (read version) | 5 |
operator+ | 5 |
operator- | 5 |
Application | 25 |
Style/Self-documentation | 5 |
Total | 100 |