|
Due
Friday, January 25, Noon (for first complete version)
Goals
|
|
Overview
This is a straightforward assignment to write a simple program in either C++ or Java
that computes the dot product of two vectors.
Be sure to meet my requirements.
You must complete this without help (other than with the mechanics
of using our system) from anyone other than me.
You must complete this assignment to my satisfaction to pass this course.
I'll give you feedback on this assignment. You'll make modifications until it meets my requirements. The due date is for your first complete attempt.
Input and Output Specification
All input is from standard input, not a file.
The first input is one integer representing the length of two vectors.
Both vectors are the same length.
That integer should be positive. If it is not, the program should print
an error message and quit.
Otherwise, the program should read values of type double to fill the two vectors, one vector at a time.
If there are not enough values, fill with zero.
(Hint: fill with zero when you create the vectors.)
Ignore any extra values.
Print all real numbers with one digit after the decimal point.
The first output should be a neatly labeled display of the contents
of the two vectors.
Label the vectors as a whole.
Print each vector on one line with spaces between elements.
Label each element with its index (e.g. 0:14 1:243 2:-4 3:75...).
Then print the dot product of the two vectors. The dot product is the sum of the products of the elements with the same index. The vectors must be the same length. The summation formula above is another representation of the dot product.
Other Requirements
Submit it as either the dotc++ or dotjava assignment.
For C++ the file should have a .cxx ending. For Java the extension must of course be
.java.
Your program must compile cleanly with no errors or warnings.
You must use appropriate functions/methods throughout this program. Pass all the parameters appropriately. If a parameter shouldn't change, make sure it can't be. Each function should do one thing well (have high cohesion).
Do not declare bigger vectors than you need.
Declare storage as locally as possible to complete the task. Do not declare global variables.
You should use your best programming style. Use descriptive names for variables and functions. Use precise commenting. I do not want to see comments on every line of code. Good code comments itself. However, each function/method other than main should have a useful comment describing what it does in terms of its parameters.
Put your name and the month of creation, a description of the problem, and a description of the inputs and outputs in a comment at the top of your program. Use consistent indenting that reflects the structure of the code. Take the time to do this assignment neatly and correctly.
This assignment will be graded on a zero/one basis. It must be completed to my satisfaction to earn a one which is then, conceptually, multiplied by your other lab grades. In other words, you have to do this, I may ask you to make changes, and I'll keep asking until you get it right.