| Date Assigned: | Thu Oct-12 |
| Date Due: | Fri Oct-13 by end of day |
1. Min/Max/Average: Write a program which loads a vector (of size SIZE = 10) of integers with values read in from the user. The program should then print all the values, the min value, the max value, and the averages of the values. Here is how your program's output should look (with user input underlined):
Please enter integer 1 of 10: 3Some Hints:
Please enter integer 2 of 10: 7
Please enter integer 3 of 10: 16
Please enter integer 4 of 10: -10
Please enter integer 5 of 10: 22
Please enter integer 6 of 10: 33
Please enter integer 7 of 10: 19
Please enter integer 8 of 10: 20
Please enter integer 9 of 10: -52
Please enter integer 10 of 10: -38The numbers are: 3, 7, 16, -10, 22, 33, 19, 20, -52, -38
The maximum number is: 33
The minimum number is: -52
The average is: 2
Goodbye!
2. Extra Credit: (This portion of the assignment has been posted for a couple days now.) For those wanting extra credit, here it is: we've done sum-of-integers and we just did sum-of-squares. Your next task, purely for extra credit, is to do sum-of-cubes. You can do this one of two ways:
- Be sure not to use the number 10 in your code, except in the one line: const int SIZE = 10;
- Make your output look exactly like the output above
- To input into the ith element of a vector v, use: cin >> v[i];
- To do this, you may want to declare integer variables min, max, and sum, and update these each time the user enters another number.
1. For modest extra credit: find a web site somewhere, or ask someone, or somehow magically learn what the proper equation is for the sum of the first N cubes. Then just empirically confirm it, as we did on our last 2 assignments.
2. For buckets of extra credit: write a program to figure out what the equation is. How? Well, first, just believe me that the equation is of the form aN4 + bN3 + cN2 + dN + e. So now plug in values for N. For example, if N = 1, this equation is just a + b + c + d + e. But we know the sum of the first N cubes is just 13 = 1. So we have the equation:
a + b + c + d + e = 1.Continuing in this manner, when N = 2 we get the equation:
16a + 8b + 4c + 2d + e = 13 + 23 = 9Do this for N=3, N=4, and N=5, and you will produce 5 equations in 5 unknowns (a,b,c,d,e), at which point you may solve for the unknowns (hint: use Gaussian Elimination -- look it up if you aren't sure what it is). Once you have these 5 unknowns, you can express the quartic (power-of-4) equation which is the sum of the first N cubes. Voila!
3. Big-Time Extra Credit: Check out AP CS Assignment 13, also on this subject. Do it (yes, you can!).