Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! I am new to C++ and don't know how to solve this problem. I need the code listed below completed using the following

Please help! I am new to C++ and don't know how to solve this problem. I need the code listed below completed using the following instructions. Thank you!

image text in transcribed

The code you should write should take 5 command line parameters:

functionid, an integer to know which function to integrate. If functionid is 1, integrate f1

a, the lower bound of the integral

b, the upper bound of the integral

n, an integer which is the number of points to compute the approximation of the integral

intensity, an integer which is the second parameter to give the the function to integrate

The code should compute the integral and output the value of the integral on stdout (and nothing else). The code should also measure the time it took to compute the integral and write that time (expressed in seconds with decimal values) to stderr.

Question: Write the described code. You can use the provided archive as a template. It contain a template code and makele to help you write the code. You should only need to complete main.cpp. You should be able to test if your code is correct using make test.

Code:

#include #include #include #include

#ifdef __cplusplus extern "C" { #endif

float f1(float x, int intensity); float f2(float x, int intensity); float f3(float x, int intensity); float f4(float x, int intensity);

#ifdef __cplusplus } #endif

int main (int argc, char* argv[]) {

if (argc

std::cerr" "<>

return -1; } return 0; }

Note that you do not need to understand numerical integration. The problem is just to evaluate b-a n-1 en ia : f (a + (i + .5) * bna) for a particular cornbination of a, b, n, and f The provided package contains multiple functions to integrate in libfunctions.a. The functions are named f1, f2, f3, f4, and take two parameters: the first one is a floating point number x where the function is computed, and the second one is intensity an operation intensity. The second parameter is used to make the function take more time

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Students also viewed these Databases questions

Question

Draw a physical data flow diagram for Problem 8.

Answered: 1 week ago

Question

Question What is a secular trust?

Answered: 1 week ago