Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will allow its user to choose one of the five mathematical

ID: 3692565 • Letter: W

Question

Write a program that will allow its user to choose one of the five mathematical functions listed below, choose either the rectangle method, trapezoid method or both methods of area estimation, the number of rectangles/trapezoids to use, and specify a starting and ending boundaries for the area to estimate.

Based on those values, your program should run the selected area estimation method(s) on the selected function with the selected range and number of rectangles/trapezoids, and report the resultant calculated estimated area beneath the function to the user.

Math functions to implement:

• f 1(x) = 2x^5 + x^3 10x + 2

• f 2(x) = 6x^2 x + 10

• f 3(x) = 5x + 3 • f 4(x) = 2x^3 + 120

• f 5(x) = 2x^2

Example program output: Choose a function (1, 2, 3, 4, 5): 5

Would you like to calculate the area using rectangles, trapezoids, 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 calculated area beneath the function between 1 and 2 is: 4.667

Extra Credit For extra credit, write your program so that it can handle ALL erroneous input by the user for each option. If the user enters an invalid choice when prompted to make a decision, your program should detect that and ask them to choose again.

Explanation / Answer

#include <stdio.h>

#include<math.h>

int main() // main execution starts
{
int cf,rule,r,a,b; //variables for the operations
printf("Choose a function (1,2,3,4,5): "); // prompting user to select funciton
scanf("%d",&cf); // reading the user data
printf("Would you like to calculate the area using rectangles, trapezoids, or both? (1, 2, 3): "); // prompting user
scanf("%d",&rule); // reading the data from user
switch(rule) // switch for the desired method or rule
{
case 1: printf("How many rectangle do you want: "); // reading data from user
scanf("%d",&r);
printf("Choose starting point: ");
scanf("%d",&a);
printf("Choose ending point: ");
scanf("%d",&b);
rectangle(r,a,b); // calling function for rectangel method
break;
case 2:
printf("How many trapiziods do you want: "); // reading required data from user
scanf("%d",&r);
printf("Choose starting point: ");
scanf("%d",&a);
printf("Choose ending point: ");
scanf("%d",&b);
trapiziodal(r,a,b); // calling trapiziods method by passing r a and b
break;
  
case 3:
printf("How many rectangle/trapiziods do you want: "); // read data from user
scanf("%d",&r);
printf("Choose starting point: ");
scanf("%d",&a);
printf("Choose ending point: ");
scanf("%d",&b);
rectangle(r,a,b); // calling both functions
trapiziodal(r,a,b);
break;
}

return 0;
}

void rectangle(int r,int a,int b) // rectangle function here
{
int i;
float c,result=0.0,temp;
c=(b-a)/r; // loading unit scale of graph if a=1 b=2 n=10 then x0=1.1, x1=1.2 ...x10=2.0;
temp=c;
switch(cf) // switch for desired function
{
case 1:
for(i=0;i<r;i++) // loop through all x values
{
result=result+2*power(c,5)+power(c,3)-10*c+2; // function calculation
c=c+temp;
}
result=temp*result;
printf("Area by rectangles is:%f ",result); // printing the result
break;
case 2:
for(i=0;i<r;i++)
{
result=result+6*power(c,5)-c+10;
c=c+temp;
}
result=temp*result;
printf("Area by rectangles is:%f ",result);
break;
  
case 3:
for(i=0;i<r;i++)
{
result=result+5*c+3;
c=c+temp;
}
result=temp*result;
printf("Area by rectangles is:%f ",result);
break;
case 4:
for(i=0;i<r;i++)
{
result=result+2*power(c,3)+120;
c=c+temp;
}
result=temp*result;
printf("Area by rectangles is:%f ",result);
break;
case 5:
for(i=0;i<r;i++)
{
result=result+2*power(c,2);
c=c+temp;
}
result=temp*result;
printf("Area by rectangles is:%f ",result);
break;
  
}
}
void trapiziodal(int r,int a,int b) // trapiziodal implementation
{
int i;
float c,result=0.0,temp,val;
c=(b-a)/r;
val=c/2;
temp=c;
switch(cf)
{
case 1:
for(i=0;i<r;i++)
{
if(i==0 ||i==r-1)
{
result=result+2*(2*power(c,5)+power(c,3)-10*c+2);
c=c+temp;
}
result=result+2*power(c,5)+power(c,3)-10*c+2;
c=c+temp;
}
result=val*result;
printf("Area by trapiziodal is:%f ",result);
break;
case 2:
for(i=0;i<r;i++)
{
if(i==0 ||i==r-1)
{
result=result+2*(6*power(c,5)-c+10);
c=c+temp;
}
result=result+6*power(c,5)-c+10;
c=c+temp;
  
}
result=val*result;
printf("Area by trapiziodal is:%f ",result);
break;
  
case 3:
for(i=0;i<r;i++)
{
if(i==0 ||i==r-1)
{
result=result+2*(5*c+3);
c=c+temp;
}
result=result+(5*c+3);
c=c+temp;
}
result=val*result;
printf("Area by trapiziodal is:%f ",result);
break;
case 4:
for(i=0;i<r;i++)
{
if(i==0 ||i==r-1)
{
result=result+2*(2*power(c,3)+120);
c=c+temp;
}
result=result+2*power(c,3)+120;
c=c+temp;
}
result=val*result;
printf("Area by trapiziodal is:%f ",result);
break;
case 5:
for(i=0;i<r;i++)
{
if(i==0 || i=r-1)
{
result=result+2*(2*power(c,2));
c=c+temp;
}
result=result+2*power(c,2);
c=c+temp;
}
result=val*result;
printf("Area by trapiziodal is:%f ",result);
break;
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote