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

2. (TCO 7) Write a function called writeData. This function is passed a string a

ID: 3529197 • Letter: 2

Question

2.(TCO 7) Write a function called writeData. This function is passed a string array, integer array, double array, and the size of the arrays.

The arrays to be passed to the writeData function are shown below:

string names[] = {"Bill","Steve","Bjarne","James","Rasmus"};

intages[] = {25, 50, 32, 75, 12};

doubleweights[] = {150.5, 175.0, 200.5, 125, 95.5};

The function does not return a value. The function writes the data in the arrays to a text file named output.txt. The data will be output to the text file in the following format:

Bill,25,150.5

Steve,50,175

Bjarne,32,200.5

James,75,125

Rasmus,12,95.5

Explanation / Answer

void writeData(string *names, int *ages, double *weights, int i)

{

int l;

for(l=0; l<i;l++)

{

cout<<names[l]<<ages[l]<<weights[l]<<endl;

}

}


main()

{

string names[] = {"Bill","Steve","Bjarne","James","Rasmus"};

int ages[] = {25, 50, 32, 75, 12};

double weights[] = {150.5, 175.0, 200.5, 125, 95.5};

int size=sizeof ages/ (sizeof ages[0]);

writeData(names,ages,weights,size);


}


PLease check the compilatation errors. Logic is correct. :)