5 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
ID: 3623081 • Letter: 5
Question
5
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;
void myfun4(int,double[][2],double[],double&);
int main()
{ifstream input;
int i,npoints;
double xydata[100][2],product[100],sum=0;
input.open("data4.txt"); //open file
if(input.fail()) //is it ok?
{ cout<<"file did not open please check it ";
system("pause");
return false;
}
input>>npoints;
for(i=0;i<npoints;i++)
input>>xydata[i][0]>>xydata[i][1];
myfun4(npoints,xydata,product,sum);
cout<<" x y xy ";
cout<<setprecision(3)<<fixed;
for(i=0;i<npoints;i++)
cout<<" "<<xydata[i][0]<<" "<<xydata[i][1]<<" "<<product[i]<<endl;
cout<<"The sum of the product xy = "<<sum<<endl;
input.close();
system("pause");
return 0;
}
void myfun4(int npoints,double xydata[][2],double product[],double& sum)
{int i;
for(i=0;i<npoints;i++)
{product[i]=xydata[i][0]*xydata[i][1];
sum+=product[i];
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.