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

PART A) 25 Points: Due 3/15/16 Write a C++ program that calculates the area unde

ID: 3690703 • Letter: P

Question

PART A) 25 Points: Due 3/15/16 Write a C++ program that calculates the area under a curve. Here is the equation: f(x) = x^2 +1.5x +4 You must prompt the user for the beginning and the ending x values. You are to assume, but not check, that the user will put in whole positive numbers. The units are inches. The program input/output should look something like this: This program calculates the area under a curve between two points on the x axis. The equation is: XXXXXXXX Please Enter the min x value: Please Enter in the max x value: The area under the curve between ‘min x’ and ‘max x’ is: ‘total’ square inches. You should calculate the area using the basic “rectangular slice” method. Set your x axis intervals at 1 inch. For example, if the user input the x range from 1 inch to 4 inches, you would have three x ranges: from 1 to 2, from 2 to 3 and 3 to 4 in which you calculate the area and make a sum of the total. When using the “rectangular slice method,” you can choose the y value at the left hand side of the rectangle or the right hand side. Either way is OK with me. Just be consistent. PART B) 25 Points: Due 3/29/16 Here is a second equation: f(x) = x^2 + 1.5x – 4 Program this equation in addition to the first. If the curve goes below the x axis, please treat that area as a “negative.” Therefore, the total area under the curve should be equal to the positive area (above the x axis) minus the area below the x- axis. Considering the for the spring 2016 class, this was not communicated clearly, students who add the two areas together will be given full credit. Ie., Mr. Blake will accept the “net” results of the two areas or the “total area” result. PART C) 50 Points: Due 3/29/16 Prompt the user for how many segments the x axis should be divided into. Ie., if the user sets the x axis range from 3” to 8”, part A and B would divide it into five segments. Now you prompt the user for how many segments should be used and do the proper calculations. For example, the user input min 3 and max 7 number of segments: 20 You now need to divided the min and max range into 20 segments Also, the user can now enter negative numbers along the x axis. For example, min point may be -3 and max point may be 8 (whereas before the limits were all positive a greater than 0) PART D) 25 Points: Due 4/19/16 Make all of the user inputs “idiot proof.” PART E) 25 Points: Due 4/26/16 Do a comparison study of the program. Meaning, the program will take more “time” when the number of x axis segments is larger. Also, the accuracy of the number should be greater, with more segments. In other words, you are trading off accuracy for run time. At what point does the number of segments provide improved accuracy vs. the “time” it take the program to execute? BONUS ROUND: 75 Points: Due May 12th Have the user input a math equation and you do the calculations. Limit it to a fifth order polynomial equation.

Explanation / Answer

ANS;

#include <iostream>
#include <math.h>
using namespace std;
float f1(int low,int up)
{
int i,total=0.0;
for(i=low;i<=up;i++)
{
total=total+(i*i+i*1.5+4);
}
return total;
}
float f2(int low,int up)
{
int i,total=0.0;
for(i=low;i<=up;i++)
{
total=total+(i*i+i*1.5-4);
}
return total;
}
int main()
{
int low,up;
cout << "This program calculates the area under a curve between two points on the x axis ";
cout<< " The FIRST equation is: f(x)=x^2 +1.5x +4";
cout<< " The SECOND equation is: f(x)=x^2 +1.5x -4";

cout << " Enter x's minimum value : ";
cin >> low;
cout << "Enter x's maximum value : ";
cin >> up;
cout << " Area in square inches for FIRST equation ";
cout << "The area under the curve between "<<low<<" and "<<up<<" is: "<<f1(low,up)<<" square inches. ";
cout << " Area in square inches for SECOND equation ";
cout << "The area under the curve between "<<low<<" and "<<up<<" is: "<<f2(low,up)<<" square inches. ";
return 0;
}