CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2010
    Posts
    146

    Reading Data from file and manipulating it

    Hello All

    Could anyone please help me with solving the problem below?

    File Data format
    A,A
    A,B
    C,E
    C,F
    And so on ... it could be up to any alphabet. The number of As and Bs and Cs and Ds in first column depends on the number of unique alphabets used in the first column. For example the unique alphabets used in this case are 2 (A,C) hence each alphabet appears in the first column of consecutive 2 rows.

    Which means
    Code:
    A:A,B,C,D
    B:B,C,D,E
    C:C,D,E,F
    D:D, ,F,G (E is missing)
    Actual Data
    A,1
    A,2
    A,3
    A,4
    C,18
    C,33
    Final Solution: Add each integer value to its previous value and store the resulting value.

    Could anyone please help me achieve this final solution?
    Thanks
    Last edited by gulHK; July 15th, 2012 at 04:00 AM.

  2. #2
    Join Date
    Jul 2012
    Posts
    13

    Re: Reading Data from file and manipulating it

    Why is E missing, and why is it only on the D row?

  3. #3
    Join Date
    Nov 2010
    Posts
    146

    Re: Reading Data from file and manipulating it

    Hi Tex

    It is not about E, any alphabet can be missing, the point I am trying to make is that where ever a value of some alphabet is missing, we should put ZERO as its value. And value of any of the alphabets in any column can be missing, not just D row.

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Reading Data from file and manipulating it

    Quote Originally Posted by gulHK
    it could be up to any alphabet.
    I believe the word that you intended is "letter" or "character" not "alphabet".

    Quote Originally Posted by gulHK
    (E is missing)
    Your example is incredibly confusing because you reuse the letters when the letters in the first column actually have nothing to do with the letters of the same name in the second column. Furthermore, it is not that "E is missing", but that you have a 0 there.

    This problem is actually quite simple: read the file line by line, and break each line into a letter and its corresponding number value. Map each letter to a vector of number values, i.e., you append this number value to the vector of that letter. When you are done processing the file, you loop over this map. For each vector in the map, you perform a cumulative sum, which can be done by adding the previous value to the current value.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Nov 2010
    Posts
    146

    Re: Reading Data from file and manipulating it

    Hello laserlight

    "you reuse the letters when the letters in the first column actually have nothing to do with the letters of the same name in the second column"

    That's how exactly the actual task looks like, it repeats the character in the second column of each "first" row for a character and yes you can refer to alphabets as characters. The value of E is missing and any character whose value is missing should be filled with a ZERO

    I hope I've made my point clear

    Thanks

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Reading Data from file and manipulating it

    This isn't the do my homework for me forum. You make an effort and we'll point you in the right direction when you're stuck. First things first. Can you open and read the file?

  7. #7
    Join Date
    Nov 2010
    Posts
    146

    Re: Reading Data from file and manipulating it

    Hello GCDEF

    Yes I can read and write a file, I can parse it and I also can make use of STL containers, I just dont know how to go about it.

  8. #8
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Reading Data from file and manipulating it

    Quote Originally Posted by gulHK
    you can refer to alphabets as characters
    This is a matter of English vocabulary: an "alphabet" is a collection of letters used in a writing system, typically specified in some given order. You could say that this is analogous to a character set, not to a character.

    Quote Originally Posted by gulHK
    That's how exactly the actual task looks like, it repeats the character in the second column of each "first" row for a character and yes you can refer to alphabets as characters. The value of E is missing and any character whose value is missing should be filled with a ZERO

    I hope I've made my point clear
    That is not clear at all, not when you mention "actual task" but provide "actual data" that looks completely different.

    Quote Originally Posted by gulHK
    Yes I can read and write a file, I can parse it and I also can make use of STL containers, I just dont know how to go about it.
    Did you read what I wrote about how to go about doing it? Of course, I was coming from an assumption about your task that does not appear to be correct, but frankly I have no idea what you are really trying to do.

    Here's one way you can clarify: post a sample of the actual data input and a sample of the expected output corresponding to that data, then explain how did you get from input to output. Then, state what exactly is the problem you're facing implementing a program that does that.
    Last edited by laserlight; July 7th, 2012 at 09:39 AM.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Reading Data from file and manipulating it

    Quote Originally Posted by gulHK View Post
    Hello GCDEF

    Yes I can read and write a file, I can parse it and I also can make use of STL containers, I just dont know how to go about it.
    I'm confused. You say you can do it, but you don't know how. That sounds like two different answers. If you can read a file, write that code and get it working. Start there. Once you get the strings in from the file, we can look at the different ways to manipulate them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured