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
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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.