• Write a C++ program p2.cpp that operates as described below.
  • Your program should accept three command line arguments. The first two arguments are names of input files, and the third argument is the name of an output file.
  • The data in all three files will be stored as comma-separated values (csv files format).
  • You can take a look at csv files with an ordinary text file editor or by using Microsoft Excel. Both views will be illustrated in the examples below.
  • The first input file contains a database arranged as a 2-dimensionsal table. The first line (row) contains column headings. Each remaining line (row) contains a data record that consists of plain-text fields separated by commas. You may assume that each file contains at most 50000 rows, and that every row contains the same number of fields which is at most 100.

Example: Here are two views of a first input file input0.csv:

First nm, Last nm, Gender,Cwid,Cred hrs, Qual pts,Gpa
John, Roe,M,44444444,40,150,3.75 Jane, Roe,F,66666666,100,260,2.6 John, Doe,M,22222222,50,140,2.8 Jane,Doe,F,88888888,80,280,3.5 Penny, Lowe,F,55555555,40,140,3.5 Lenny,Lowe,M,11111111,100,280,2.8 Denny, Lowe,M,99999999,80,260,3.25 Benny,Lowe,M,77777777,120,90,0.75 Jenny, Lowe,F,33333333,50,90,1.8 Zoe,Coe,F,0,50,130,2.6
  • The second input file specifies how your program should sort the data from the first input file. Each row of the second file has three fields, as follows. The first field is a column name from the first input file, the second field specifies the direction (ascend or descend), and the third field specifies the data type (string, int, or float). The first row denotes the primary key for sorting, the second row (if it exists) denotes the secondary key, etc.

Example: Here are two views of a second input file input0-7.csv:

Gender,ascend,string
Gpa,descend,float
Last nm,ascend,string
  • The output file should contain the same data as the first input file, with the rows rearranged as specified in the second input file. However, the first line of the output file should still contain the column headings.

Example: Next suppose we run the following commands:

g++ -Wall-std=c++11 p2.cpp -o p2
./p2 input0.csv input0-7.csv output0-7.csv

Here are two views of the expected output file outputo-7.csv:

First nm, Last nm,Gender,Cwid,Cred hrs, Qual pts,Gpa
Jane,Doe,F,88888888,80,280,3.5 Penny, Lowe,F,55555555,40,140,3.5 Zoe,Coe,F,0,50,130,2.6 Jane, Roe,F,66666666,100,260,2.6 Jenny,Lowe,F,33333333,50,90,1.8 John, Roe,M,44444444,40,150,3.75 Denny,Lowe,M,99999999,80,260,3.25 John Doe,M,22222222,50,140,2.8 Lenny,Lowe,M,11111111,100,280,2.8 Benny, Lowe,M,77777777,120,90,0.75
  • Please carefully read the following requirements:
    • You may only use these libraries: < iostream>, < fstream>, < sstream>, < string>, < cctype>, < vector>.
    • Your input and output files must be in csv file format as in the examples above.
  • Your program should define and use a class that stores the information found in a csv file. This class should contain at least the number of rows, the number of columns, and the data itself.
  • Because the exact size of the database is not known in advance, your program should use an efficient sorting algorithm (O(n Ig n) running time). Otherwise your program might be too slow for some larger data files.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.