When completing this programming assignment, you may work with up to one other person. No groups of more than two are permitted.
In PA 2.1: Area under the curve, you were tasked with estimating the area under a function within a giving x interval by breaking it into three trapezoids and calculating the area of each of those. We can improve our estimation by breaking the function into more segments, but that's burdensome and error prone to do in code without defining some functions to help us out.
In this PA, you will revisit PA 2.1 and add a function called ComputeTrapezoidArea, which takes four parameters: x1, y1, x2, and y2, where (x1, y1) is the coordinate of the upper left point of the trapezoid and (x2, y2) is the coordinate of the upper right point. The lower left point is assumed to be (x1, 0) and the lower right point is assumed to be (x2, 0). The function should return the area of the trapezoid as a double.
In addition, modify your program to take one additional input from the user: the number of trapezoids to use. Your program will have to break the provided x-interval into that many segments (instead of thirds like you did in PA 2.1).
Copy the following header and specifications checklist and paste it at the top of your source code. As you complete the specifications, fill in the [ ] next to that specification in the check list (e.g., like this: [x]). I will not grade submissions with missing specifications; please do not submit if you cannot check all of them off. This specs checklist is essentially a way for you to self grade before you submit your program.
// Specifications checklist for PA Option 8.1: Area under the curve with functions
// General specs:
// [ ] the header includes your name and anyone you worked with
// [ ] the header includes this specifications checklist with all completed
// specifications checked off: [x]
// [ ] the code is indented properly (inside of every block, code is indented
// one more tab)
// [ ] each chunk of code that "hangs together" (works toward a higher level goal):
// [ ] includes a brief, useful comment above it
// [ ] is separated from the next chunk by a blank line
// [ ] there are no really long lines of code or comments (if you have long
// lines, split them across multiple shorter lines)
// [ ] identifiers are well named
// [ ] the program compiles
// [ ] the program runs without crashing or hanging
// [ ] all output and prompts look clean (correct spelling, capitalization,
// nothing squished)
// [ ] all prompts make it clear what data the user is expected to enter and in
// what format and work as expected
// [ ] every function includes a JavaDoc above it that specifies all present
// parameters and return values.
// [ ] parameters are specified as pass by reference only when necessary
// Specific specs:
// [ ] the program prompts and reads from the user the following information:
// [ ] a, b, c in the polynomial y = a + bx + cx^2
// [ ] the starting and ending interval of x to calculate the area between
// [ ] the number of trapezoids to use
// [ ] the program approximates the area under the polynomial within the given
// interval using the specified number of equally sized, non-overlapping trapezoids
// [ ] the program outputs the approximate area at the end with a label (e.g.,
// "Approximate area under y = 1 + 2x + 3x^2 between x = [0.1, 3] is 40.244")
// [ ] the program is accurate -- your program's approximations match the expected
// results at the bottom of the assignment page
// [ ] the program includes a function called ComputeTrapezoidArea that...
// [ ] takes four parameters (the x,y coordinates of the upper left and upper
// right corners of the trapezoid)
// [ ] returns the area of the trapezoid as a double
// [ ] assumes the lower left and lower right points are located at y=0
// [ ] handles trapezoids that face either direction -- either the upper left *or*
// the upper right could be taller
// [ ] the ComputerTrapezoidArea function is properly called in main
Here are the expected results for a number of polynomials:
||Number of trapezoids
||Approximate area under
|1 + 2x + 3x2
|1 + 2x + 3x2
|5 - x + 2x2
(note: the second coefficient is -1)
|1 + x + x2
|3 + 4x - 0.1x2
If you are working with a partner, both of you must submit individually.