Need help in my homework problem C++ : Question1: For this problem, you are to c
ID: 3574998 • Letter: N
Question
Need help in my homework problem C++ :
Question1:
For this problem, you are to code a C++ function called Array2File () that has 3 parameters. The first parameter is an ofstream& object that has been initialized to a text file and opened for output before the function was invoked. The second parameter is an array of double values that was initialized from the beginning of the array before the function was invoked. The third parameter is an int that represents the number of initialized values in the array. The function Array2File () should display every initialized element of the array parameter to a separate line of the text file parameter. No comments, additional subprograms or main () program are necessary.
For this problem, you are to code a C++ function called Array2File that has 3 parameters. The first parameter is an ofstream& object that has been initialized to a text file and opened for output before the function was invoked. The second parameter is an array of double values that was initialized from the beginning of the array before the function was invoked. The third parameter is an int that represents the number of initialized values in the array. The function Array2File should display every initialized element of the array parameter to a separate line of the text file parameter. No comments, additional subprograms or main program are necessary. Be sure to strike the Enter key before clicking on the Save button.Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
void Array2File (ofstream&,double[],int);
int main()
{
ofstream out("out.txt");
double arr[6]={1,2,3,4,5,5};
int n =sizeof(arr)/sizeof(arr[0]);
Array2File(out,arr,n);
return 0;
}
void Array2File (ofstream& op,double arr[],int n)
{
if(op == NULL)
cout<<"File not existed";
else
for(int i=0;i<n;i++)
{
op<<arr[i]<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.