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

Correct any errors in the following code segments: The following code should wri

ID: 3900501 • Letter: C

Question

Correct any errors in the following code segments:

The following code should write 100 empty ClientData objects to the ofstream object outCredit, which
has already been successfully opened.

ClientData blankClient; // constructor zeros out each data member // output 100 blank records to file for ( int i = 0; i < 100; i++ ) outCredit.write( ( blankClient ), sizeof( ClientData ) );

The following line of code should create fstream object outCredit attached to file "credit.dat" for input
and output of fixed-length records.

fstream outCredit( "credit.dat", ios::in & ios::out & ios::binary );

Explanation / Answer

The code is correct and should work fine but you can make an array of ClientData objects and then write them one by one if you want 100 empty objects.