Question: Programming Language : C++ Using the code below, I need help getting the input file to the output file, instructions are below, example.csv file is

Programming Language : C++

Using the code below, I need help getting the input file to the output file, instructions are below, example.csv file is below the code

Open the file and read the data into a multi-dimensional array.

The array should have two dimensions. The primary (first) dimension should contain one row (record) of data. The second dimension should contain one element (field) of data. All array items should be declared as string type. No consideration should be made for what information is represented by the data.

b. Open an output file named:

out.txt

A "flat file" is a text file that opens in a text editor. It contains no special or unreadable characters. A flat file is created using standard file i/o.

c. Write each data element from the multi-dimensional array to the output file.

To make the columns of the output file fixed-width you will have to insert the number of spaces necessary to start each column at the correct position. The data order should match the input file, with the first row in the input file being the first row in the output file.

d. Close the input file before opening the output file. Remember to close the output file when you are done with it.

// Headers #include "stdafx.h" #include #include #include

using namespace std;

string Align(string strIn, int iWidth) { string strOut; // padding

// add padding for (int i = 0; i < iWidth - strIn.length(); i++) strOut += " ";

return strOut; // return padding }

int _tmain(int argc, _TCHAR* argv[])

{ // variables

const int Rows = 9; // number of rows in file const int Fields = 11; // number of fields in file string strData[Rows][Fields]; // 2-dimentional array

ifstream inFile; // handle for input file ofstream outFile; // handle for output file

inFile.open("example.csv"); // opens input file

if (inFile.fail()) // if file not found { cout << "File did not open, please check for any errors" << endl; // display error message system("pause"); // pause program on error message exit(1); // exit program } for (int i = 0; i < Rows; i++) // loop for rows for (int j = 0; i < Fields; j++) { if (j == Fields - 1) getline(inFile, strData[i][j], ' '); else getline(inFile, strData[i][j], ','); }

inFile.close(); // done with input file, close it outFile.open("out.txt"); // open output file for write (ofstream)

for (int i = 0; i < Rows; i++) { outFile << strData[i][0] << Align(strData[i][0], 4) << strData[i][1] << Align(strData[i][1], 22) << strData[i][2] << Align(strData[i][2], 11) << strData[i][3] << Align(strData[i][3], 11) << strData[i][4] << Align(strData[i][4], 10) << strData[i][5] << Align(strData[i][5], 11) << strData[i][6] << Align(strData[i][6], 10) << strData[i][7] << Align(strData[i][7], 10) << strData[i][8] << Align(strData[i][8], 10) << strData[i][9] << Align(strData[i][9], 10) << strData[i][10] << endl; }

outFile.close(); // done with output file, close it

system("Pause"); // pauses program return 0; // closes program

}

example.csv contains this code

CRN,Subj,Num,Title,Days,Meetdates,Times,Credits,Instructor,Room,Max Enroll 80005,HS,051,Intro Human Service,T,08/13-12/16,06:00 PM-08:50 PM,3.0,Piper-Jefferson V,811,50 80007,HS,053,Special Populations,R,08/13-12/16,09:30 AM-12:20 PM,3.0,Piper-Jefferson V,811,35 80008,HS,055,Case Management,W,08/13-12/16,12:00 PM-02:50 PM,3.0,Cabrera S,811,35 80009,ANTH,002,Cultural Anthro,MWF,08/13-12/16,11:00 AM-11:50 AM,3.0,Taylor-Hill L,802,50 80010,ANTH,002,Cultural Anthro,W,08/13-12/16,06:00 PM-08:50 PM,3.0,Gravely S,802,50 80011,ANTH,002,Cultural Anthro,TR,08/13-12/16,08:00 AM-09:15 AM,3.0,Raposa T,107-A,50 80013,ANTH,001,Physical Anthro,MWF,08/13-12/16,09:00 AM-09:50 AM,3.0,Taylor-Hill L,802,50 80014,ANTH,001,Physical Anthro,TR,08/13-12/16,12:30 PM-01:45 PM,3.0,Taylor-Hill L,107-A,50

Output Should look similar to with all the clases also

CRN Subj Num Title Days Meetdates Times Credits Instructor Room Max Enroll

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!