### Trying to get the correct output!!!!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130`` ``````#include #include 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); double rect_integral(double a, double b, int n, int choice); double trap_integral(double a, double b, int n, int choice); const char * funcname[6] = { "", "5x^4 + 3x^3 - 10x + 2", "x^2 - 10", "40x + 5", "x^3", "20x^2 + 10x - 2" }; int main () { int choice; int n; double a; double b; double h; double x; double area; bool trap = false; bool rect = false; cout << "Functions available: \n\n"; for (int i=1; i<6; i++) cout << " " << i << " " << funcname[i] << '\n'; cout << endl; cout << "Choose a function (1, 2, 3, 4, 5, other(quit)) " << endl; cin >> choice; if (choice >= 1 && choice <= 5) { char method = ' '; do { cout << "Would you like to calculate the area using the rectangle," << " trapezoid, or both (1, 2, 3): " << endl; cin >> method; } while (method < '1' || method > '3'); switch (method) { case '1': rect = true; cout <<"How many rectangles do you want? " << endl; break; case '2': trap = true; cout <<"How many trapezoids do you want? " << endl; break; case '3': trap = true; rect = true; cout <<"How many rectangles/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; if (rect) { cout << "The area under " << funcname[choice] << " between " << a << " and " << b << " is: " << rect_integral(a, b, n, choice) << endl; } if (trap) { cout << "The area under " << funcname[choice] << " between " << a << " and " << b << " is: " << trap_integral(a, b, n, choice) << endl; } } return 0; } double func_1 (double x) { return 5.0*x*x*x*x + 3.0*x*x*x - 10.0*x + 2.0; } double func_2 (double x) { return x*x - 10.0; } double func_3 (double x) { return 40.0*x + 5; } double func_4 (double x) { return x*x*x; } double func_5 (double x) { return 20.0*x*x + 10.0*x - 2.0; } double rect_integral(double a, double b, int n, int choice) { // here insert the code to calculate the integral return 1.0; // dummy value } double trap_integral(double a, double b, int n, int choice) { // here insert the code to calculate the integral return 2.0; // dummy value }``````

this code compiles but I need to get the program to do this:

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

I need the program to output 29.25 but I cant figure out what to. Help please. help with code!

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
Topic archived. No new replies allowed.