| |||
Problem 01 | |||
Modify the program ArrayGrades to use an input correction loop
so that it will only accept grades in the range 0 to 100 (inclusive), prompting the
user to re-enter if they supply a grade out of range.
For each of the remaining problems we will show just the method that solves the problem. At the end we give a program that tests all the individual methods.
| |||
Problem 02 | |||
Write a method which takes an array of doubles and returns
the sum of the squares of the elements in the array.
| |||
Problem 03 | |||
Write a method which takes an array of doubles and returns
the largest value in the array.
Make sure you do not make any assumptions about the possible range of values in the array.
In particular, don't assume the numbers are all positive, and don't rely on knowing the
value of the smallest possible java
| |||
Problem 04 | |||
|
Add to the last program a method which takes two arrays and computes and returns the
sum of the squares of the placewise difference between the elements of the two arrays.
| |||
Problem 05 | |||
Add a method that computes the dot-product of two vectors.
Recall that for two n-dimensional vectors, A and B,
A.B = A1B1 + ... + AnBn
| |||
Problem 06 | |||
|
Add a method that computes the length (or, magnitude), |A|, of a vector, A, which is the
square root of the sum of the squares of the individual components. Note that you can
compute the sum of the squares manually (using a loop), or note that it is the result of taking the
dot product of the vector with itself.
| |||
Problem 07 | |||
Recall that for two n-dimensional vectors, A and B, the dot-product also satifies
the equation:
A.B = |A||B|cos(theta)where theta is the angle between the two vectors. Use this fact, the dot product method from the last problem, and the method Math.acos to write a method which, given two vectors,
computes and returns the angle theta (in radians) between them.
| |||
Unified Solution: | |||
| |||
Last modified August 28 for Fall 99 cs5 by fleck@cs.hmc.edu
This page copyright ©1998 by Joshua S. Hodas. It was built with Frontier on a Macintosh . Last rebuilt on Sat, Oct 31, 1998 at 5:46:58 PM. | |
http://www.cs.hmc.edu/~hodas/courses/cs5/week_09/labsolutions.html | |