I've tried this from all angles and its proving to be difficult

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KelvinThee
    New Member
    • Jul 2018
    • 3

    I've tried this from all angles and its proving to be difficult

    //reads data from the ICSA csv file
    if (!inputICSA.is_ open())cout<<"E RROR: FILE NOT LOCATED\n";

    string a_admission, a_name, a_fname, a_gender;

    cout << "\n\tICS A\n\n";

    while (inputICSA.good ())
    {
    getline(inputIC SA, a_admission, ',');
    getline(inputIC SA, a_name, ',');
    getline(inputIC SA, a_fname, ',');
    getline(inputIC SA, a_gender);

    inputICSA.get() ;

    cout << "Admission No: " << a_admission << "\t" << "Name: " << a_name << a_fname << "\t" << "gender: " << a_gender << endl;

    }
    I'm required to import three csv files and then sort them to make two new csv files from the shuffle. I've only been able to import the three csv files and i've been stuck at that. I'm a newbie hence the difficulties.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What do you mean by sort?

    What are the two new CSV files? Are you splitting by gender?


    Need more info here. I don't see where a sort fits in.

    Comment

    • KelvinThee
      New Member
      • Jul 2018
      • 3

      #3
      I'm supposed to create two new csv files after the shuffle. Yes, i'm supposed to split by gender.

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 656

        #4
        Here's a pseudo code/algo I have come up with:

        You need five file pointer variables.

        Let's say: var1, var2 and var3: for reading from the existing files (ios::in mode)

        var4 and var5: for writing to the new files (ios:: in | ios::out mode , since both reading and writing are to be done with the new files).

        The basic idea is to read from the existing files and place that data accordingly to the new files using some 'if' conditions.


        Code:
        [B]while (var1.good()){	
          READ a_admission, a_name, a_fname, a_gender from the file using var1
        
          if(a_gender=='1'){
               //It is now clear (with the help of a_gender)that the data belongs to the first newly created file
               //Therefore, pointer dealing with the first split is to be used i.e. var4 for writing
               //Since the data should be written in the sorted form (assuming the sorting 
                 takes place as per the names), the place of where to put that data is to be 
                 decided
               -CODE to determine the proper location
               -Insertion of the data using 'var4'
          }
          else if(a_gender=='2'){
               //using var5 to write to the second created file
               -CODE to determine the proper location
               -Insertion of the data using 'var5'
          }
        }
        while (var2.good()){
             -READING with var2
             -same as above-
        }
        while (var3.good()){
             -READING with var3
             -same as above-
        }[/B]
        You may also require the functions like seekp, seekg etc. for the proper positioning of the file pointer before reading/writing.

        Comment

        • KelvinThee
          New Member
          • Jul 2018
          • 3

          #5
          Thanks alot for your input. When you say code to determine the proper location, which algorithm is the best to use?

          Comment

          • dev7060
            Recognized Expert Contributor
            • Mar 2017
            • 656

            #6
            Not sure about any best algo. You can google things for help and implement the one which suits you the best.

            Comment

            Working...