okay so I have gotten this far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include<iostream>
#include<cmath>
using std::cin;
using std::cout;
using std::endl;
double func_1(double);
double func_2(double);
double func_3(double);
double func_4(double);
double func_5(double);
int main () {
int choice;
double n;
double a;
double b;
cout << "Choose a function (1, 2, 3, 4, 5, other(quit)) " << endl;
cin >> choice;
if (choice == 1)
{
cout <<"How many trapezoids do you want? " << endl;
cin >> n;
cout <<"Please select a starting point, a: " << endl;
cin >> a;
cout <<"Please select an ending point, b: " << endl;
cin >> b;
cout <<"The area under " << "5x^4+3x^3-10x+2" << "between a and b is: " << func_1 << endl;
return 0;
}
}
double func_1 (double x)
{
cout << 5.0*x*x*x*x + 3.0*x*x*x - 10.0*x + 2.0;
}
double func_2 (double x)
{
cout << x*x - 10.0;
}
double func_3 (double x)
{
cout << 40.0*x + 5;
}
double func_4 (double x)
{
cout << x*x*x;
}
double func_5 (double x)
{
cout << 20.0*x*x + 10.0*x - 2.0;
}
| |
This is what I have so far and this is my assignment:
Write a program to use the area of rectangles and/or trapezoids to find the area under a curve. We take the integral of a function to find the area under a curve.
variables used:
n = number of rectangles and/or trapezoids
a = beginning x value
b = ending x value
h = width of each rectangle/trapezoid, (b-a)/n
f(x) = height of rectangle
(f(x1)+f(x2))/2 = height of trapezoid
Area = width*height
Integration Program Definition: Your program should determine the area under these different functions,
f1(x) = 5x4 + 3x3 – 10x + 2
f2(x) = x2 – 10
f3(x) = 40x + 5
f4(x) = x3
f5(x) = 20x2 + 10x – 2
The functions are bounded by any interval on the x-axis, including both positive and negative values!!!. The area calculated will be determined by the user's choice of function and method to use to calculate the integral, and it is possible for the user to choose to see the area for one function calculated by both methods. For example:
Choose a function (1, 2, 3, 4, 5, other(quit)): 1
Would you like to calculate the area using the rectangle, trapezoid, or both (1, 2, 3): 2
How many trapezoids do you want? 1000
Please select a starting point, a = 1
Please select an ending point, b = 2
The area under 5x4 + 3x3 – 10x + 2 between 1 and 2 is 29.25.
Program Description in more detail:
Your program needs to adhere to the following guidelines:
If the user chooses to see the area calculated by both methods, each method should receive their own number of rectangles or trapezoids as input and return the value from the calculation.
Your program should continue running until the user no longer wants to calculate the area under a curve.
You should use procedural decomposition and have functions for f1(x), f2(x), f3(x), f4(x), and f5(x), as well as functions for calculating the area using the rectangle vs. trapezoid method.
Program Input:
- Starting and ending points for the area
- Function to calculate the area, i.e. f1, f2, f3, f4, f5
- Function/Procedure(s) for calculating the area, i.e. rect, trap, both
- Number of rectangles and/or trapezoids to use
Program Output:
- The function being evaluated
- Starting and ending points for the integral
- Number of rectangles and/or trapezoids used
- The area calculated by the method(s)
Cant figure this out. Please help.