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

0.4 0.43 0.62 0.95 0.99 1.22 0.25 0.86 0.91 0.34 1.25 0.88 Write a C++ program w

ID: 3623080 • Letter: 0

Question

0.4
0.43
0.62
0.95
0.99
1.22
0.25
0.86
0.91
0.34
1.25
0.88

Write a C++ program which consists of a main function and a single result double function called double myfun3(double[ ], double, double, int) The main function: Opens a file called data3.txt. The file is found by right clicking here. Asks the user to input from the keyboard two numbers, call them a and b. Reads all the numbers from the data file, into a single array x, using a while loop that continues until failure (use the C++ function fail()). Uses the single result function myfun3 to calculate the summation of a / (1 + b*x(i)) for i from 0 to n-1; The main program then prints the result of the summation to the screen. Your output should look like this:

Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
double myfun3(double[],double,double,int);
int main()
{ifstream input;
double a,b;
int i=0;
double x[100],product[100],sum;
input.open("data3.txt");           //open file
if(input.fail())             //is it ok?
    { cout<<"file did not open please check it ";
    system("pause");
    return 0;
    }
cout<<"Enter values for a and b ";
cin>>a>>b;  
input>>x[i++];
while(!input.fail())
    input>>x[i++];
i--;
sum=myfun3(x,a,b,i);
cout<<"The sum of the functions values = "<<sum<<endl;
input.close();
system("pause");
return 0;
}
double myfun3(double x[],double a,double b,int n)
{int i;
double sum=0;
for(i=0;i<n;i++)
    sum+=(a/(1+b*x[i]));
return sum;
}