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

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

Write a C++ program which consists of a main function and a void function called void myfun4(int, double[ ][2], double[ ]. double&) The main function: Opens a file called data4.txt. The file is found here. Reads the first number from the file and assigns it the name npoints Reads the next npoints rows of data from the file into a two dimensional array called xydata. Calls the void function myfun4 and sends the array to the function along with the value of npoints The function finds the product of the xydata points in each row and stores them in a second array. The function finds the sum of the product values. The function returns, by reference, the values of xy product arrays and the sum of product values. The main function prints out the values of the original array, the product array, and the sum of the product array values in a well formatted table. Your output should look like this:

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];
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote