|
-
July 7th, 2012, 06:21 AM
#1
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.
-
July 7th, 2012, 08:19 AM
#2
Re: Reading Data from file and manipulating it
Why is E missing, and why is it only on the D row?
-
July 7th, 2012, 08:28 AM
#3
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.
-
July 7th, 2012, 08:39 AM
#4
Re: Reading Data from file and manipulating it
 Originally Posted by gulHK
it could be up to any alphabet.
I believe the word that you intended is "letter" or "character" not "alphabet".
 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.
-
July 7th, 2012, 08:57 AM
#5
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
-
July 7th, 2012, 09:00 AM
#6
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?
-
July 7th, 2012, 09:06 AM
#7
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.
-
July 7th, 2012, 09:37 AM
#8
Re: Reading Data from file and manipulating it
 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.
 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.
 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.
-
July 7th, 2012, 04:04 PM
#9
Re: Reading Data from file and manipulating it
 Originally Posted by gulHK
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|