Using the C++ Code below answer this question. What are your takeaways from this? Elaborate on what you have to say abou

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Using the C++ Code below answer this question. What are your takeaways from this? Elaborate on what you have to say abou

Post by answerhappygod »

Using the C++ Code below answer this question.
What are your takeaways from this? Elaborate on what you have tosay about this program and in meeting all the "Blocks".
4.Blocks
Implemented a routine to compute for the approximate area underthe curve.
Implemented a routine to compute for the true area under thecurve using integral.
Used linked listing (chosen from singly, doubly, or circular andno arrays allowed) to store and display the area of eachtrapezoid.
Used an accumulator variable to compound the area stored in eachnode->data in the linked list.
#include<iostream>
#include<iomanip>
using namespace std;
float f(float x){
return x + (3 * x * x);
}
float F(float x){
return (x * x / 2) + (x * x * x);
}
int main(){
float a , b;
int n;
cout << "Enter value of a: " ;
cin >> a;
cout << "Enter value of b: ";
cin >> b;
cout << "Specify the number of trapezoids: ";
cin >> n;
cout << endl;
float integral = F(b) - F(a);
float h = (float)((b - a) / n);
float *trapz = new float[n];
float sum_trapz = 0;
int i = 0;
while(a <= b){
float ai = a;
float bi = a + h;
trapz = ((f(ai) + f(bi)) / 2) * (h);
sum_trapz += trapz;
cout << "Trapezoid area " << i + 1 << " = "<< fixed << setprecision(4)
<< trapz << " units squared." << endl;
i++;
a = bi;
}
cout << "\n\nArea using trapezoid method = " <<sum_trapz << " units Squared" << endl;
cout << "The area using integral calculus = " <<integral << " units squared" << endl;
float rel_err = ((integral - sum_trapz) / integral) * 100;
cout << "Percenr error = " << rel_err << "%"<< endl;
cout << "Press any key to continue ...";
char ch;
cin >> ch;
return 0;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply