Programming Language : C++ Write a program which reads the .csv filedata from ex
ID: 3864612 • Letter: P
Question
Programming Language : C++
Write a program which reads the .csv filedata from
example.csv
43154 MATH 114 Pre Algebra MW 08/13-12/16 12:00 PM-02:15 PM
74567 CHEM 128 Intro Chems MW 10/08-12/09 05:30 PM-07:45 PM
22412 ENG 001 College English M 08/13-12/16 06:00 PM-07:50 PM
Use the data to perform the following steps:
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.
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.
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.
Close the input file before opening the output file.
Remember to close the output file when you are done with it.
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.
Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
int main(){
ofstream ofile("out.txt");
string **arr=new string*[3];
for(int i=0;i<3;i++)
arr[i]=new string[10];
for(int i=0;i<3;i++)
for(int j=0;j<10;j++)
cin>>arr[i][j];
for(int i=0;i<3;i++){
for(int j=0;j<10;j++){
ofile<<arr[i][j]<<" ";
}
ofile<<endl;
}
return 0;
}
out.txt
43154 MATH 114 Pre Algebra MW 08/13-12/16 12:00 PM-02:15 PM
74567 CHEM 128 Intro Chems MW 10/08-12/09 05:30 PM-07:45 PM
22412 ENG 001 College English M 08/13-12/16 06:00 PM-07:50 PM
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.